IOS 3D touch的使用
1、在info.plist文件中设置3D touch的标题,图片(图片系统自带提供7种,也可自定义),提供了7种,但是实际最多只可以显示4个
系统自带7种图标样式分别是:Compose,Play,Pause,Add,Location,Search,Share,在plist配置的时候应该就是前面加UIApplicationShortcutIconType,比如UIApplicationShortcutIconTypeSearch
info.plist文件中设置如下:
[key]UIApplicationShortcutItems[/key]
[array]
[dict]
[key]UIApplicationShortcutItemIconType[/key]
[string]UIApplicationShortcutIconTypeShare[/string]
[key]UIApplicationShortcutItemTitle[/key]
[string]Share[/string]
[key]UIApplicationShortcutItemType[/key]
[string]-11.UITouchText.share[/string]
[/dict]
[/array]
2、在AppDelegate.m中添加3D touch对应的方法,实现3D touch的触发事件
//处理3D Touch触发事件的
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
//判断是我们在info.plist中设置的哪一个唯一标识
if ([shortcutItem.type isEqualToString:@"touch"]) {
MineCentreViewController *MineNV=[[MineCentreViewController alloc]init];
//设置当前的VC 为rootVC
[self.window.rootViewController presentViewController:MineNV animated:YES completion:^{
}];
}
else if ([shortcutItem.type isEqualToString:@"touch1"])
{
NSArray *arr=@[@"hello 3D Touch"];
//UIActivityViewController为分享的弹出框,arr为分享的内容
UIActivityViewController *ActVC=[[UIActivityViewController alloc]initWithActivityItems:arr applicationActivities:nil];
[self.window.rootViewController presentViewController:ActVC animated:YES completion:^{
}];
}
else{
MainPageController *MainNV=[[MainPageController alloc]init];
//设置当前的VC 为rootVC
[self.window.rootViewController presentViewController:MainNV animated:YES completion:^{
}];
}
}