给项目app加入了图标deep press交互,实现3D Touch,只支持6S及以上手机。
其实就是类似微信支付宝重按图标进入扫码页面的那种功能。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self createItemsWithIcons];
return YES;
}
这里就是设置了图标重按后出现的列表,最多支持4个item,可以设置文字和图标。
/**
* 3D Touch Icons
*/
- (void)createItemsWithIcons {
//这是icon的图片,对图片有要求,不符合规则显示不来哦
UIMutableApplicationShortcutItem *shortItem1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"punch" localizedTitle:@"打卡"];
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"iCon1"];
shortItem1.icon = icon1;
UIMutableApplicationShortcutItem *shortItem2 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"punchRecord" localizedTitle:@"打卡记录"];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"iCon2"];
shortItem2.icon = icon2;
NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem1, shortItem2,nil];
NSLog(@"%@", shortItems);
[[UIApplication sharedApplication] setShortcutItems:shortItems];
}
具体页面跳转的实现写在这里头,我是通过获取导航条控制器进行的跳转
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
DLog(@"A shortcut item was pressed. It was %@.", shortcutItem.localizedTitle);
if ([shortcutItem.type isEqualToString:@"punch"]) {
DLog(@"punch");
MMDrawerController *mmdController = (MMDrawerController *)self.window.rootViewController;
[mmdController closeDrawerAnimated:NO completion:^(BOOL finished) {
BaseNavigationCongroller *baseVC = (BaseNavigationCongroller *)mmdController.centerViewController;
MainVC *main = baseVC.viewControllers[0];
[main judgeLocationEnable];
}];
}
if ([shortcutItem.type isEqualToString:@"punchRecord"]) {
DLog(@"punchRecord");
Record *recordVC = [[Record alloc]init];
MMDrawerController *mmdController = (MMDrawerController *)self.window.rootViewController;
[mmdController closeDrawerAnimated:NO completion:^(BOOL finished) {
BaseNavigationCongroller *baseVC = (BaseNavigationCongroller *)mmdController.centerViewController;
if ([baseVC.topViewController isKindOfClass:[Record class]]) {
DLog(@"已经在打卡记录页面");
}else{
[baseVC pushViewController:recordVC animated:NO];
[mmdController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
}
}];
}
}