While developing iOS apps, developers are focusing on various technologies to deliver a richer user experience. 3D touch is one such technology introduced by Apple that completely transforms the mobile app development. 3D touch made its debut in the iPhone in September 2014 and it is accepted as a brilliant piece of screen technology. This feature is borrowed from Apple Watch, and it allows users to apply various levels of pressure on the iPhone’s touch screen.
3D touch is a newly added feature to the iPhone and is based on force touch technology. It gives the users a new set of gestures to deal with the apps' icons and details on the screen.
The idea behind 3D Touch is to sense the amount of pressure your finger applies to the screen and trigger various actions. 3D Touch enables soft press and hard press rather than the short press or long-press.
The 3D Touch has 3 levels of input based on pressure sensitivity. This technology is not available on all iPhones - iPhone XR does not support it for example. Here are the iPhone models that get 3D touch:
Before moving deep into 3D features and implementation, it is important to ensure your device compatibility with 3D Touch. iOS developers use this code snippet to check 3D Touch availability in the given device:
This feature is available on the home screen and can be used to quickly access a certain part of the app to trigger an action. If you force touch an app icon; a menu will be presented. It enables you to quickly perform basic app-specific actions and find useful information. Camera, for example, provides a shortcut for taking a selfie, record video, take a photo, and record Sio-mo and as shown below:
The quick action is subdivided into static and dynamic actions.
The quick actions, which are specific to the app and it will never change are generated as static quick actions. These actions are developed at compile-time, and it will stay the same all the time. They will be available immediately on the device soon after the app installation even before its first launch. Here we defined four actions as static using the project’s Info.plist file:
Quick action entry in info.plist file
Here is the code snippet for defining static actions:
Quick Action handler in AppDelegate file
Static quick action in action
Dynamic actions can be generated as well as deleted at run time. It reflects the user behavior, but it won’t appear until the code of these actions is run. To implement quick action, you need to create an instance of the UIApplicationShortcutItem object as shown below:
You can define any number of quick actions, but not more than four of them will be showed on the screen. In addition, static quick actions will be prioritized. So if you define two static actions and three dynamic actions, all of two static actions will be displayed followed by two of the dynamic quick actions.
Peek & Pop are pressure-sensitive gestures. If you press the app deeply, your interaction with the app proceeds through two phases:
Some of the actions where Peek and Pop used for:
To implement Peek and Pop, you need to add the UIViewControllerPreviewingDelegate function. The following code snippet integrates the 3D touch into the iOS application:
3D touch in UITableViewController
3DTouch in UICollectionViewController
As a result, if you touch the app Dog lists, a preview will be open up. It includes the list of Dogs on the selected breed as shown below:
When you press a little harder on any of the Dog images, it will pop up the full-screen image of the dog:
Peek and Pop example in action:
Examples that show the true potential of 3D touch on the iPhone:
Overall, we can say that the future of 3D touch is very bright as most enterprises hire iOS developers to unlock all its potential in their app. Enterprises saw the light and updating their apps to support this new way of access on the iPhone.