美文网首页
app图标上的3D Touch效果

app图标上的3D Touch效果

作者: 倪大头 | 来源:发表于2018-01-26 10:00 被阅读187次
- (void)setup3DTouch:(UIApplication *)application {
    /*
     type 该item 唯一标识符
     localizedTitle :标题
     localizedSubtitle:副标题
     icon:icon图标 可以使用系统类型 也可以使用自定义的图片
     userInfo:用户信息字典 自定义参数,完成具体功能需求
     */
    UIApplicationShortcutIcon *QRCodeIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCapturePhoto];
    UIApplicationShortcutItem *QRCodeItem = [[UIApplicationShortcutItem alloc]initWithType:@"QRCode" localizedTitle:@"扫码" localizedSubtitle:@"" icon:QRCodeIcon userInfo:nil];
    
    UIApplicationShortcutIcon *recordingIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePlay];
    UIApplicationShortcutItem *recordingItem = [[UIApplicationShortcutItem alloc]initWithType:@"Recording" localizedTitle:@"录音" localizedSubtitle:@"" icon:recordingIcon userInfo:nil];
    
    //将items添加到app图标
    application.shortcutItems = @[QRCodeItem,recordingItem];
}
//图标3DTouch回调
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
    UINavigationController *nav = (UINavigationController *)tabBarController.selectedViewController;
    if ([shortcutItem.type isEqualToString:@"QRCode"]) {
        QRCodeViewController *qrvc = [[QRCodeViewController alloc]init];
        qrvc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:qrvc animated:YES];
    }else if ([shortcutItem.type isEqualToString:@"Recording"]) {
        RecordingViewController *recordvc = [[RecordingViewController alloc]init];
        recordvc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:recordvc animated:YES];
    }
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    tabBarController = [[TabBarController alloc]init];
    self.window.rootViewController = tabBarController;
    
    [self.window makeKeyAndVisible];
    
    [self setup3DTouch:application];//3D Touch调用
    
    return YES;
}

相关文章

网友评论

      本文标题:app图标上的3D Touch效果

      本文链接:https://www.haomeiwen.com/subject/nzjvaxtx.html