iOS开发 实现3DTouch
1.添加3DTouch
(我是自己封装的 只是在app 启动的时候吊起)
1.1判断是不是可以使用(ios9 之前不可以使用)不判断可能会导致奔溃
- (BOOL)is3DTouchWithController:(UIViewController *)controller
if (version >= 9) {
if (controller.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable){
return YES;
} else {
return NO;
}
} else {
return NO;
}
}
1.2.添加3DTouch
UIApplicationShortcutItem *paly = [[UIApplicationShortcutItem alloc] initWithType:@"123"
localizedTitle:@"表演"
localizedSubtitle:nil
icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"icon_bar_performClick"]
userInfo:nil];
[UIApplication sharedApplication].shortcutItems = [NSArray arrayWithObjects:paly, nil];
2.在appdelegate中实现点击
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
completionHandler:(void(^)(BOOL succeeded))completionHandler
{
shortcutItem.type可以实现传值(就是上面的123)
}