3D Touch Utility
3D Touch technology was first introduced on the iPhone 6s and 6s+. Devices that support 3D Touch are equipped with a screen that is sensitive to touch force, which measures the pressure on the screen. 3D Touch technology allows users to press an app icon on the home screen and get quick access to some features presented in the app. Also, within an application, a user can gain access to some features.

Since iOS 9, Apple has made the 3D Touch APIs available:

  • Home Screen Quick Action API
  • UIKit Display and Display API
  • Web Visualization and Visualization API
  • UITouch force properties

To find out if a device is compatible with 3D Touch technology, you should read the forceTouchCapability values. While the app is running, a user can disable 3D Touch, so this value must be checked in the traitCollectionDidChange delegate method.

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {

if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
NSLog(@"3D Touch is available");
} else {
NSLog(@"3D Touch is not available on this device");
}
}

3D Touch Quick Actions
There are two types of home screen quick actions: dynamic and static.

Static actions are defined in the Info.plist file inside UIApplicationShortcutItems training.

Dynamic actions must be added to the UI app application object in the shortcutItems property. You can use two methods for creation:

Method 1

init(type: String,

localizedTitle: String,
localizedSubtitle: String?,
icon: UIApplicationShortcutIcon?,
userInfo: [AnyHashable: Any]? = nil)

This method creates a Home screen dynamic quick action with a header, optional subheader, optional icon, and user information dictionary.

Method 2

convenience init(type: String,

localizedTitle: String)

Create a Home screen dynamic quick action with a header but no icon.

Quick Actions Controller
application func(application: UIApplication,

performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completeHandler: Bool -> Void) {

let didHandle: Bool = /* handle quick action using shortItem */

completion handler (handler)

}

func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Boolean {

var performAdditionalHandling = true

whether to let shortcutItem = launch options?[UIApplicationLaunchOptionsShortcutItemKey]

I’ve got? UIApplicationShortcutItem {

/* handle quick action using shortItem */

perform additional handling = false

}

return performAdditionalHandling

}

UIKit Display and Display API
This API is used for content preview (fast) and further transition. new methods in UIViewController for ViewController registration and deregistration allow notifications about whether it will be used by 3D Touch. Additionally, new protocols have been added for 3D Touch support.

View Controller Log:
-(id)registerToPreviewWithDelegate:(id)delegate sourceView:(UIView *)sourceView;

Look:

– (UIViewController *)previewingContext: (id)previewingContext viewControllerForLocation:(CGPoint)location {

// check if we’re not already showing a preview controller

Yeah ([self.presentedViewController isKindOfClass:[PreviewViewController class]]) {

return zero;

}

// shallow click: return the preview controller here (look)

Storyboard UIS *storyboard = [UIStoryboard storyboardWithName:@”Main” bundle:nil];

UIViewController *previewController = [storyboard instantiateViewControllerWithIdentifier:@”PreviewView”];

returns the preview controller;

}

Commit:

– (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {

// deep press: open the confirmation view controller (pop)

Storyboard UIS *storyboard = [UIStoryboard storyboardWithName:@”Main” bundle:nil];

UIViewController *commitController = [storyboard instantiateViewControllerWithIdentifier:@”CommitView”];

[self showViewController:commitController sender:self];

// alternatively, use the view controller provided here (viewControllerToCommit)

}

In the preview, you can also add UIPreviewAction Y UIPreviewActionGroup

UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Action 1"

style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action,
UIViewController * _Nonnull previewViewController) {
NSLog(@"Action 1 triggered");
}];

// add them to an arrary

NSArray *actions = @[action1, action2, action3];

// add all actions to a group

UIPreviewActionGroup *group1 = [UIPreviewActionGroup actionGroupWithTitle:@"Action Group"
style:UIPreviewActionStyleDefault actions:actions];
NSArray *group = @[group1];

The true potential of 3D Touch
As developers learn about the benefits of 3D technology, it becomes clear that it will become a staple.

Leave a Reply

Your email address will not be published. Required fields are marked *