How To Add 3D Touch To Your IOS App
3D bit Utility
The 3D bit technology was initially introduced on the iPhone 6s and 6s+. Devices supporting 3D bit area unit equipped with a faucet force sensitive show, an activity the pressure on the screen. The 3D bit technology permits users to press Associate in Nursing app icon on the house screen and acquire fast access to some practicality given within the app. Also, inside Associate in the Nursing app, a user will get access to some options.
From iOS 9, Apple created 3D bit genus Apis available:
Home Screen fast Action API
UIKit peek and pop API
Web read peek and pop API
UITouch force properties
In order to seek out whether or not a tool supports the 3D bit technology, you've got to scan out the forceTouchCapability values. whereas the app is functioning, a user will close up a 3D bit, therefore this worth should be checked within the traitCollectionDidChange delegate technique.
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
NSLog(@"3D bit is available");
} else {
NSLog(@"3D bit isn't offered on this device");
}
}
3D bit fast Actions
There area unit 2 styles of Home Screen fast Actions: dynamic and static.
Static actions area unit outlined within the information. the plist file inside the UIApplicationShortcutItems array.
Dynamic actions ought to be adscititious to the UIApplication application object within the shortcut items property. you'll be able to use 2 strategies for creation:
Method 1
init(type: String,
localizedTitle: String,
localizedSubtitle: String?,
icon: UIApplicationShortcutIcon?,
userInfo: [AnyHashable: Any]? = nil)
This technique creates a Home screen dynamic fast action with a header, facultative subheader, facultative icon, and facultative user information wordbook.
Method 2
convenience init(type: String,
localized title: String)
Creates a Home screen dynamic fast action with a header however with no icon.
Quick Actions Handler
func application(application: UIApplication,
performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: Bool -> Void) the short action mistreatment shortcutItem */
completionHandler(didHandle)
}
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool the fast action mistreatment shortcutItem */
performAdditionalHandling = false
}
return performAdditionalHandling
}
UIKit peek and pop API
This API is employed for content preview (quick) and more transition thereto. New strategies in UIViewController for ViewController registration and registration cancellation enable notifications on whether or not it's planning to be employed by 3D bit. in addition adscititious area unit new protocols for 3D bit support.
ViewController registration:
-(id)registerForPreviewingWithDelegate:(id)delegate sourceView:(UIView *)sourceView;
Peek:
- (UIViewController *)previewingContext: (id)previewingContext viewControllerForLocation:(CGPoint)location
// shallow press: come back the preview controller here (peek)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *previewController = [storyboard instantiateViewControllerWithIdentifier:@"PreviewView"];
return previewController;
}
Commit:
- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit point out the commit read controller (pop)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *commitController = [storyboard instantiateViewControllerWithIdentifier:@"CommitView"];
[self showViewController:commitController sender:self];
// as an alternative, use the read the controller that is being provided here (viewControllerToCommit)
}
In a preview, you'll be able to additionally add UIPreviewAction and UIPreviewActionGroup
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Action 1"
style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action,
UIViewController * _Nonnull previewViewController)
How To Add 3D Touch To Your IOS App
Reviewed by IIS Daily
on
March 18, 2019
Rating:
No comments: