3D touch utility
3D Touch technology was first introduced on the iPhone 6s and 6s+. Devices that support 3D Touch are equipped with a touch force-sensitive screen, 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 Visualization API
  • Visualization API and web visualization
  • UITouch force properties

To find out if a device supports 3D Touch technology, you should read the
forceTouchCapability values. While the app is running, a user can disable 3D Touch, so this value should 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 User interface application application object in Items shortcut 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 controller (handler)

}

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

var performAdditionalHandling = true

if leave shortcutItem = launch options?[UIApplicationLaunchOptionsShortcutItemKey]

to have? UIApplicationShortcutItem {

/* handle quick action using shortItem */

perform additional handling = false

}

return performAdditionalHandling

}

UIKit Display and Visualization API
This API is used for (fast) content preview and further transition. new methods in UIViewController by ViewController registration and deregistration allow notifications about whether 3D Touch will use it. Also, 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 displaying a preview controller

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

return zero;

}

//shallow click: return preview handler here (look)

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

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

returns the preview controller;

}

Engage:

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

// deep press: open 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 the benefits of 3D technology, it’s clear that it will become a staple.

Leave a Reply

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