自从iPhone 6s / 6s Plus 发布之后,3D Touch给了APP一种新的活力,对于大部分的果粉或者年轻人来说,应该已经很习惯这个新特征了,很多的主流APP也在第一时间适配了3D Touch,为了让自己的APP显得高大上,适配3D Touch就是必不可少的一步了,如何对3D Touch进行开发,网上也有很多的博客,楼主只是学习着应用一下。
在众多的博客中,很感谢下面的博客,楼主也很推荐大家去看一下
iOS9 3D Touch 使用教程
<key>UIApplicationShortcutItems</key> <array> <dict> <key>UIApplicationShortcutItemIconType</key> <string>UIApplicationShortcutIconTypeShare</string> <key>UIApplicationShortcutItemType</key> <string>Title1</string> <key>UIApplicationShortcutItemSubtitle</key> <string>SubTitle1</string> <key>UIApplicationShortcutItemTitle</key> <string>StateTitle1</string> </dict> <dict> <key>UIApplicationShortcutItemType</key> <string>Title2</string> <key>UIApplicationShortcutItemSubtitle</key> <string>SubTitle3</string> <key>UIApplicationShortcutItemTitle</key> <string>StateTitle2</string> </dict> <dict> <key>UIApplicationShortcutItemType</key> <string>Title3</string> <key>UIApplicationShortcutItemSubtitle</key> <string>SubTitle3</string> <key>UIApplicationShortcutItemTitle</key> <string>StateTitle3</string> </dict> </array>
//必须设置值的键 UIApplicationShortcutItemType //位置标识符 UIApplicationShortcutItemTitle //标题 //可选设置值得键 UIApplicationShortcutItemIconType //显示图标系统类型 UIAPPlicationShortcutItemIconFile //显示图标的图片名 UIAPPlicationShortcutItemUserInfo //用户信息字典信息,自定义参数
typedef NS_ENUM(NSInteger, UIApplicationShortcutIconType) { UIApplicationShortcutIconTypeCompose, UIApplicationShortcutIconTypePlay, UIApplicationShortcutIconTypePause, UIApplicationShortcutIconTypeAdd, UIApplicationShortcutIconTypeLocation, UIApplicationShortcutIconTypeSearch, UIApplicationShortcutIconTypeShare, UIApplicationShortcutIconTypeProhibit NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeContact NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeHome NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeMarkLocation NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeFavorite NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeLove NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeCloud NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeInvitation NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeConfirmation NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeMail NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeMessage NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeDate NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeTime NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeCapturePhoto NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeCaptureVideo NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeTask NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeTaskCompleted NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeAlarm NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeBookmark NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeShuffle NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeAudio NS_ENUM_AVAILABLE_IOS(9_1), UIApplicationShortcutIconTypeUpdate NS_ENUM_AVAILABLE_IOS(9_1) } NS_ENUM_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED;
#ifdef __IPHONE_9_0 //因为这个类是iOS 9_0 之后的,所以预编译指令,在iOS 9_0 之后进行编译 /** * 创建3D Touch选项 */ - (void)createShortcutItems { //最简单的形式 UIApplicationShortcutItem * item1 = [[UIApplicationShortcutItem alloc]initWithType:@"item1" localizedTitle:@"Item1"]; //可以自定义选项 UIApplicationShortcutIcon * icon2 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd]; UIApplicationShortcutItem * item2 = [[UIApplicationShortcutItem alloc]initWithType:@"item2" localizedTitle:@"Item2" localizedSubtitle:@"Item2" icon:icon2 userInfo:nil]; //使用自定义的图片定义选项 UIApplicationShortcutIcon * icon3 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"delete"]; UIApplicationShortcutItem * item3 = [[UIApplicationShortcutItem alloc]initWithType:@"item3" localizedTitle:@"Item3" localizedSubtitle:@"item3" icon:icon3 userInfo:nil]; //响应到APP端 [UIApplication sharedApplication].shortcutItems = @[item3,item2,item1]; } #endif
#ifdef __IPHONE_9_0 [self createShortcutItems]; #endif
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { NSLog(@"shortcutType = %@",shortcutItem.type); }