3D Touch是一种立体触控技术,被苹果称为新一代多点触控技术,是在Apple Watch上采用的Force Touch,屏幕可感应不同的感压力度触控。3D Touch,苹果iPhone 6s的新功能,看起来类似 PC 上的右键。有Peek Pop 两种新手势。
2015年9月10日,苹果在新品发布会上宣布了3D-Touch功能。
2016年6月13日,苹果开发者大会WWDC在旧金山召开,会议宣布可以在待机画面用3D Touch操作通知。
-
支持机型6s以上
一.3D触摸功能添加分为两种(1)静态标签(填写plist文件)(2)动态标签(代码撸)
(1)静态标签
先添加了一个UIApplicationShortcutItems的数组,这个数组中添加的元素就是对应的静态标签,在每个标签中我们需要添加一些设置的键值:
必填项(下面两个键值是必须设置的):
UIApplicationShortcutItemType
这个键值设置一个快捷通道类型的 字符串
UIApplicationShortcutItemTitle
这个键值设置标签的标题
选填项(下面这些键值不是必须设置的)
:
UIApplicationShortcutItemSubtitle
设置标签的副标题
UIApplicationShortcutItemIconType
设置标签图标类型
UIApplicationShortcutItemIconFile
设置标签的图标文件
UIApplicationShortcutItemUserInfo
设置信息字典(用于传值)
(1)动态标签
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//3D Touch按压程序图标的快捷项
//快捷菜单的图标
UIApplicationShortcutIcon *icon1=[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCaptureVideo];
UIApplicationShortcutIcon *icon2=[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
UIApplicationShortcutIcon *icon3=[UIApplicationShortcutIcon iconWithTemplateImageName:@"search"];
//快捷菜单
UIApplicationShortcutItem *item1=[[UIApplicationShortcutItem alloc]initWithType:@"1"
localizedTitle:@"发布"
localizedSubtitle:nil
icon:icon1
userInfo:nil];
UIApplicationShortcutItem *item2=[[UIApplicationShortcutItem alloc]initWithType:@"1"
localizedTitle:@"列表"
localizedSubtitle:nil
icon:icon2
userInfo:nil];
UIApplicationShortcutItem *item3=[[UIApplicationShortcutItem alloc]initWithType:@"1"
localizedTitle:@"慈善"
localizedSubtitle:nil
icon:icon3
userInfo:nil];
//设置app的快捷菜单
[[UIApplication sharedApplication] setShortcutItems:@[item1,item2,item3]];
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
BOOL gai = [UserDefaults boolForKey:@"isLogin"];
NSLog(@"状态 = %d",gai);
if (gai == YES ) {
if([shortcutItem.localizedTitle isEqualToString:@"发布"])
{
ZongViewController *zong = [[ZongViewController alloc]init];
[nav pushViewController:zong animated:NO];
}
else if([shortcutItem.localizedTitle isEqualToString:@"列表"])
{
LastnewViewController *last = [[ LastnewViewController alloc]init];
[nav pushViewController:last animated:NO];
}
else if([shortcutItem.localizedTitle isEqualToString:@"慈善"])
{
CharitiesViewController *charit = [[ CharitiesViewController alloc]init];
[nav pushViewController:charit animated:NO];
}
}else {
LoginViewController *login = [[ LoginViewController alloc]init];
[nav pushViewController:login animated:NO];
}
}```