IOS 3DTouch Development Routines Daquan

Source: Internet
Author: User

Today's rest, first came to nothing on their own look, about 3d Touch, after reading their own hands to try a bit, it is not difficult to feel,

After a lot of search, so far, found that there are three ways to achieve;

First: Add a field to the info file

This way, the most direct, but also the most convenient, but there are some shortcomings, is the display icon problem, this way can only display, the system gives the icon,

Required (The following two key values must be set):

Uiapplicationshortcutitemtype This key value to set a shortcut channel type string

Uiapplicationshortcutitemtitle The title of this key value setting label

Optional (these key values are not required):

Uiapplicationshortcutitemsubtitle Setting the subtitle of a label

Uiapplicationshortcutitemicontype setting label icon type

Uiapplicationshortcutitemiconfile icon file for the Settings tab

Uiapplicationshortcutitemuserinfo setting information dictionary (for value transfer)

Uiapplicationshortcutitemicontype types can only be used with the system type, if you want to change their own icon, then this method is not suitable for

There are several types of systems available below:

Just add this push gesture callback method to the Appdelegate.

1- (void) Application: (UIApplication *) application Performactionforshortcutitem: (Uiapplicationshortcutitem *) ShortcutItem Completionhandler: (void(^) (BOOL succeeded)) completionhandler{2     //determine the unique identity we set previously3     if([Shortcutitem.type isequaltostring:@"-11.uitouchtext.share"]){4Nsarray *arr = @[@"Hello 3D Touch"];5Uiactivityviewcontroller *VC =[[Uiactivityviewcontroller Alloc]initwithactivityitems:arr Applicationactivities:nil];6         //set the current VC to ROOTVC7[Self.window.rootViewController PRESENTVIEWCONTROLLER:VC Animated:yes completion:^{8             9 Ten              }]; One              A}Else if([Shortcutitem.type isequaltostring:@"Three.3d.tou"]) -     { -Threeviewcontroller *secod =[[Threeviewcontroller alloc]init]; the [nav pushviewcontroller:secod animated:yes]; -      -      -      +     } -}
The second type: Dynamic tags (others are so called, a little unclear why)

This method can perfectly compensate for the disadvantage of the first method. But it also has a drawback, is the direct app installed after the run once, in order to call out 3d Touch gestures, the first is installed on the can.

Nonsense not much to say, directly on the code,

-(void) add3dtouch{/** * Uiapplicationshortcutitem Create tag class * Uiapplicationshortcuticon create Variable Label class * Uiapplicationshortcutitem Create Label The class of Icon*///Add the Icon-type that comes with your systemUiapplicationshortcuticon *icon =[Uiapplicationshortcuticon Iconwithtype:uiapplicationshortcuticontypehome]; Uiapplicationshortcutitem*item = [[Uiapplicationshortcutitem alloc]initwithtype:@"Mian"Localizedtitle:@"Home Page"Localizedsubtitle:@"FRISTVC"Icon:icon Userinfo:nil];//add your own iconUiapplicationshortcuticon *icon1 = [Uiapplicationshortcuticon iconwithtemplateimagename:@"Second"]; Uiapplicationshortcutitem*ITEM1 = [[Uiapplicationshortcutitem alloc]initwithtype:@"Second"Localizedtitle:@"SECONDVC"Localizedsubtitle:@"Second-sub-title"Icon:icon1 Userinfo:nil]; //if the system icon does not meet the requirements, you can use the + (Instancetype) Iconwithtemplateimagename: (NSString *) templateimagename; //to add a custom picture as a label, note that the image must be added to the bundle beforehandUiapplicationshortcuticon *icon2 = [Uiapplicationshortcuticon iconwithtemplateimagename:@"three.jpg"]; Uiapplicationshortcutitem*ITEM2 = [[Uiapplicationshortcutitem alloc]initwithtype:@"three"Localizedtitle:@"THREEVC"Localizedsubtitle:@"Three-sub-title"Icon:icon2 Userinfo:nil]; //Shortcutitems is an array[UIApplication Sharedapplication].shortcutitems =@[item,item1,item2]; }

However, it is important to note that when calling this method, it is necessary to judge that the system version must be greater than 9.0, or it will collapse

// determine if the system version is greater than 9.0 and then set (if not judged to crash in the low-version system)    if 9.0 ) {        [self add3dtouch];    }

The callback method is the same as the first method.

Third: Trigger mechanism refer to the circle of friends 3dtouch open the picture and swipe up, a menu view appears below

Original Blog Address: http://www.cnblogs.com/n1ckyxu/p/5096316.html

The original blog is explained in detail, and there is a demo link, I do not explain here,

Personally, this method is more troublesome than the previous 2 kinds, but the use is not the same. The top 2 are for 3d Touch on the app icon, but the third is for the 3d Touch effect in your app

IOS 3DTouch Development Routines Daquan

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.