IOS-how to integrate iOS9 3D Touch, ios-ios9

Source: Internet
Author: User

IOS-how to integrate iOS9 3D Touch, ios-ios9
1. preface with the arrival of 6 s, 3DTouch was rapidly popularized by various popular apps. After the bloggers personally experience it, they found that the ease of use was greatly improved. Then they wrote a Demo according to the document, I hope to provide some help to anyone who needs it. 2. How to use 3D Touch? . Click the APP icon on the main interface to bring up the Touch menu.

InAppleDelegateFile program entry Configuration:

Didfinishlaunchingwitexceptions

// Add a 3D Touch menu to the App icon // take a photo // The menu icon uiapplicationshortshortcuticon * iconCamera = [uiapplicationshortshortcuticon iconWithType: uiapplicationshortshortcuticontypeadd]; // menu text uimutableapplicationshortshortcutitem * itemCamera = [[uimutableapplicationshortshortcutitem alloc] initWithType: @ "1" localizedTitle: @ ""]; // bind information to the specified menu itemCamera. icon = iconCamera; // album // menu icon uiapplicationshortshortcuticon * iconPhotoLibrary = [uiapplicationshortshortcuticon iconWithType: Custom]; // menu text ** itemPhotoLibrary = [UIMutableApplicationShortcutItem alloc] initWithType: @ "2" localizedTitle: @ "album"]; // bind information to the specified menu itemPhotoLibrary. icon = iconPhotoLibrary; // bind to App icon application. export cutitems = @ [itemCamera, itemPhotoLibrary];

In the pop-up menu, you need to click to jump to the specified page

Here we will use a newly added method in AppDelegate.

- (void)application:(UIApplication *)application performActionForShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem completionHandler:(nonnull void (^)(BOOL))completionHandler;

After that, we need to perform the jump operation in this method.

// Photography type if ([cutitem. type isEqualToString: @ "1"]) {UIImagePickerController * picker = [[UIImagePickerController alloc] init]; // initialize picker. allowsEditing = YES; // You can edit picker. sourceType = UIImagePickerControllerSourceTypeCamera; [self. window. rootViewController presentViewController: picker animated: YES completion: nil]; // enter the camera page} // album type if ([Picture cutitem. type isEqualToString: @ "2"]) {UIImagePickerController * picker = [[UIImagePickerController alloc] init]; // initialize picker. allowsEditing = YES; // You can edit picker. sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self. window. rootViewController presentViewController: picker animated: YES completion: nil]; // enter the Image Library

After clicking, the camera and album will be displayed respectively.

 

2.2. 3DTouch Click Preview to add the menu at the bottom of the preview. First, we need to distinguish between preview by light and long by gesture. here we need to perform a basic check during initialization. 
Nterface ViewController () <UIViewControllerPreviewingDelegate> {UILongPressGestureRecognizer * _ longPress;} @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; required * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPressToDo)]; _ longPress = longPressGr;} // check whether the page is in 3DTouch-(void) check3DTouch {if (self. traitCollection. forceTouchCapability = UIForceTouchCapabilityAvailable) {[self registerForPreviewingWithDelegate: self sourceView: self. view]; NSLog (@ "3D Touch enabled"); // long press stop _ longPress. enabled = NO;} else {_ longPress. enabled = YES ;}}-(void) viewWillAppear :( BOOL) animated {[self check3DTouch];}

 

Then we need to implement the UIViewControllerPreviewingDelegate protocol.

@interface ViewController () <UIViewControllerPreviewingDelegate>
// Then implement the proxy method-(UIViewController *) previewingContext :( id <UIViewControllerPreviewing>) previewingContext viewControllerForLocation :( CGPoint) location;

 

# Pragma mark> 3D touch proxy method // tap to enter the floating preview page-(UIViewController *) previewingContext :( id <UIViewControllerPreviewing>) previewingContext viewControllerForLocation :( CGPoint) location {// note that I did not perform specific location processing because of the test. If you need to locate the Cell location of the specific image, you can use location to retrieve the specified Cell ASPreviewViewController * vc = [[ASPreviewViewController alloc] init] Through tableView convertPoint; vc. view. frame = self. view. frame; UIImageView * er = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "123.png"]; vc. view = er; return vc ;}

 

After completion, you can achieve the basic preview effect:

 

Finally, we add

Add the slide menu at the bottom during Preview

Implement the UIViewControllerPreviewingDelegate protocol in the preview controller ASPreviewViewController we just created

Then rewrite its proxy method.

- (NSArray<id<UIPreviewActionItem>> *)previewActionItems;

 

// Action Items-(NSArray <id <UIPreviewActionItem> *) previewActionItems {UIPreviewAction * p1 = [UIPreviewAction actionWithTitle: @ "share" style: UIPreviewActionStyleDefault handler: ^ (UIPreviewAction * _ Nonnull action, UIViewController * _ Nonnull previewViewController) {NSLog (@ "click to share") ;}]; UIPreviewAction * p2 = [UIPreviewAction actionWithTitle: @ "favorites" style: UIPreviewActionStyleDefault handler: ^ (UIPreviewAction * _ Nonnull action, UIViewController * _ Nonnull previewViewController) {NSLog (@ "Click favorites");}]; NSArray * actions = @ [p1, p2]; return actions ;}

 

Author: Clear Saup
Source: http://www.cnblogs.com/qingche/
The copyright of this article is shared by the author and the blog. You are welcome to repost it, but you must keep this statement and provide a connection to the original article on the article page.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.