3D Touch has also been a long time, this time to take a good look at the experience to share with you
1. The main interface re-press the app icon to pop up the touch menu
1.1 Static Quick Options
(iOS array) gives the app a quick option to specify a static home screen, which contains a dictionary array, each containing detailed information about a quick option. You can specify a static quick option to use a dictionary array for your app.
Uiapplicationshortcutitems (iOS array) gives the app a quick option to specify a static home screen, which contains a dictionary array, each containing detailed information about a quick option. You can specify a static quick option to use a dictionary array for your app.
Statically defined keys that are frequently used at run time:
Uiapplicationshortcutitemtype (must be used) to distinguish the classification from other quick options
Uiapplicationshortcutitemtitle (must use) Quick options to display the caption
Uiapplicationshortcutitemsubtitle Quick Options Display sub-headings
Uiapplicationshortcutitemicontype picture types are provided by the system (many new image types are added after iOS9.1)
Uiapplicationshortcutitemiconfile Custom Icons
Uiapplicationshortcutitemuserinfo Additional Information
2. Dynamic Quick Options
Implement the following code in Appdelegate
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {2 Uiapplicationshortcutitem * item = [[Uiapplicationshortcutitem alloc]initwithtype:@ "and" localizedtitle:@ "Search Listings" localizedsubtitle:@ "One-step arrival to the designated property" Icon:[uiapplicationshortcuticon Iconwithtype:uiapplicationshortcuticontypesearch] Userinfo:nil];3 Uiapplicationshortcutitem * item1 = [[Uiapplicationshortcutitem alloc]initwithtype:@ "three" localizedtitle:@ "near the localizedsubtitle:@" Icon:[uiapplicationshortcuticon Iconwithtype: Uiapplicationshortcuticontypemarklocation] userinfo:nil];4 5 [uiapplication sharedapplication]. Shortcutitems = @[item,item1];
3. How to trigger when item is selected
1-(void) Application: (UIApplication *) application Performactionforshortcutitem: (nonnull Uiapplicationshortcutitem * ) Shortcutitem Completionhandler: (nonnull void (^) (BOOL)) completionhandler{// Use Shortcutitem.type to determine which item is clicked, to perform different actions
2 if ([Shortcutitem.type isequaltostring:@ "One"]) {3 Uitabbarcontroller *mytab = (uitabbarcontroller*) SELF.W Indow.rootviewcontroller; 4 Mytab.selectedindex = 0; 5}else if ([Shortcutitem.type isequaltostring:@ "]) {6 SEARCHVC *SEARCHVC = [[SEARCHVC alloc]init]; 7 Uitabbarcontroller *mytab = (uitabbarcontroller*) Self.window.rootViewController; 8 Uinavigationcontroller *mynav = [Mytab.viewcontrollers firstobject]; 9 [Mynav PUSHVIEWCONTROLLER:SEARCHVC animated:yes];10//[Self.window.rootViewController Presentviewcontrol LER:SEARCHVC animated:yes completion:nil];11}else{12 FPHNEARBYVC *VC = [[Fphnearbyvc alloc] Init];13 Uitabbarcontroller *mytab = (uitabbarcontroller*) self.window.rootviewcontroller;14 UINavigationController *myNAV = [mytab.viewcontrollers firstobject];15 vc.hidesbottombarwhenpushed = yes;16 [Mynav PUSHVIEWCONTROLLER:VC Animated:yes];17}18 CompletionhandLer (YES); 19}
4.APP internal Peek and pop usage (for example, use in TableView)
First comply with the Protocol Uiviewcontrollerpreviewingdelegate
Detect if there is 3Dtouch;
1-(void) check3dtouch{2 if (self.traitCollection.forceTouchCapability = = uiforcetouchcapabilityavailable) 3 {4 NSLog (@ "3D Touch on"); 5 6 } 7 else{8 9 }10}
Here's how to implement the appropriate proxy method
Peek Proxy method, tap to trigger pop-up VC
1-(Uiviewcontroller *) Previewingcontext: (ID <UIViewControllerPreviewing>) previewingcontext Viewcontrollerforlocation: (cgpoint) location{2 nsindexpath *indexpath = [_tableview Indexpathforcell: ( uitableviewcell*) [Previewingcontext Sourceview]; 3//through [Previewingcontext Sourceview] get the corresponding cell; 4 NEWVC *VC = [[FPHNEWHOUSEDETAILVC alloc] init]; 5 Newmodel * model= [_tableview ObjectAtIndex:indexPath.row]; 6 vc.pid = house.id; 7 8 NSLog (@ "%@", location); 9 return vc;10}
The agent method of Pop, where the VC to be entered can be processed, such as hiding tabbar;11-(void) Previewingcontext: (ID <UIViewControllerPreviewing>) Previewingcontext Commitviewcontroller: (Uiviewcontroller *) viewControllerToCommit12 { viewcontrollertocommit.hidesbottombarwhenpushed = yes;14 [self showviewcontroller:viewcontrollertocommit SENDER:SELF];15}
Note:TableView in
-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
method, you must register the proxy method for each cell as follows
[Self registerforpreviewingwithdelegate:self Sourceview:cell];
5. Add the bottom menu when previewing
Add the following code to the VC that you want to preview:
1-(nsarray<id<uipreviewactionitem>> *) Previewactionitems 2 {3 uipreviewaction * Action1 = [ Uipreviewaction actionwithtitle:@ "Title 1" style:1 handler:^ (uipreviewaction * _nonnull action, Uiviewcontroller * _Nonnull Previewviewcontroller) {4 NSLog (@ "Title 1"); 5 }]; 6 7 uipreviewaction * Action2 = [uipreviewaction actionwithtitle:@ "Title 2" style:0 handler:^ (uipreviewaction * _nonnull action, Uiviewcontroller * _nonnull Previewviewcontroller) {8 NSLog (@ "Title 2"), 9 }];11 uipreviewaction * Action3 = [uipreviewaction actionwithtitle:@ "Title 3" Style:2 handler:^ (uipreviewaction * _nonnull action, Uiviewcontroller * _nonnull Previewviewcontroller) { NSLog (@ "Title 3") ,}];14 nsarray * actions = @[action1,action2, Action3];16 return actions;18}
What to do when the block is directly written and clicked
Final effect:
Practical application of the
3Dtouch (application in TableView)