美文网首页
iOS 3D-Touch 实现

iOS 3D-Touch 实现

作者: 风___________ | 来源:发表于2018-06-01 19:29 被阅读15次

    1. 添加按钮(最多添加四个):

    // 我实在AppDelegate中调用添加的此方法。根据运行的时间顺序,你也可以把它放在根视图控制器中
    - (void)threeDtouch{
        UIApplicationShortcutItem *codeItem = [[UIApplicationShortcutItem alloc]initWithType:TOUCH_CODE localizedTitle:KapLocalizedString(Touch_Code) localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"nav_code"] userInfo:nil];
        UIApplicationShortcutItem *infoItem = [[UIApplicationShortcutItem alloc]initWithType:TOUCH_MESSAGE localizedTitle:KapLocalizedString(Touch_Message) localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"nav_message"] userInfo:nil];
        UIApplicationShortcutItem *writeItem = [[UIApplicationShortcutItem alloc]initWithType:TOUCH_WRITE localizedTitle:KapLocalizedString(Touch_Write) localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"nav_add_friend"] userInfo:nil];
        UIApplicationShortcutItem *draftBox = [[UIApplicationShortcutItem alloc]initWithType:TOUCH_DRAFTBOX localizedTitle:KapLocalizedString(Touch_DraftBox) localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"nav_draftbox"] userInfo:nil];
        [UIApplication sharedApplication].shortcutItems = @[draftBox,writeItem,infoItem,codeItem];
    }
    

    2. AppDelegate中添加回调

    - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
        // 没登录则跳到登录页面
        // if(!isLogin) return;
        if ([shortcutItem.type isEqualToString:TOUCH_CODE]) {
            return;
        }
        if ([shortcutItem.type isEqualToString:TOUCH_MESSAGE]) {
            return;
        }
        if ([shortcutItem.type isEqualToString:TOUCH_WRITE]) {
            return;
        }
        if ([shortcutItem.type isEqualToString:TOUCH_DRAFTBOX]) {
            return;
        }
    }
    

    3. 3D-Touch 被点击之后,程序的反应(如果没不处于运行,且不是挂起)

    1. 先走 didFinishLaunchingWithOptions方法:完成页面的加载
    2. 加载window的rootcontroller
    3. 最后回调 - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler;
    方法。进行程序的跳转
    

    相关文章

      网友评论

          本文标题:iOS 3D-Touch 实现

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