3D Touch Quick Actions (快捷菜单) 的创建

效果如下:


6E6A80BB2F9387E584F8A93AE97F4FD3.jpg

主要代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self configRootViewController];

    // 动态创建  3D Touch 的 Quick Actions(快捷菜单)
    UIApplicationShortcutItem *item1=[[UIApplicationShortcutItem alloc]initWithType:@"two" localizedTitle:@"购买商城" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeLove] userInfo:nil];

    UIApplicationShortcutItem *item2=[[UIApplicationShortcutItem alloc]initWithType:@"three" localizedTitle:@"查看信息" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"kejian@2x.png"] userInfo:nil];
    [UIApplication sharedApplication].shortcutItems=@[item1,item2];



    if (launchOptions[@"UIApplicationLaunchOptionsShortcutItemKey"]== nil)
    {
        self.window.rootViewController=[TabBarController new];
        return YES;
    }
    else
    {
        UIApplicationShortcutItem *item=[launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];

        // 根据我们设置的唯一标识判断
        if([item.type isEqualToString:@"one"])
        {
            TabBarController *tabbar=[TabBarController new];
            tabbar.selectedIndex=0;
            self.window.rootViewController=tabbar;
        }
        return NO;
    }

    return YES;
}

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
    // 根据我们设置的唯一标识判断
    if([shortcutItem.type isEqualToString:@"one"])
    {
        TabBarController *tabbar=[TabBarController new];
        tabbar.selectedIndex=0;
        self.window.rootViewController=tabbar;
    }
    // 根据我们设置的 title 判断
    if ([shortcutItem.localizedTitle isEqual:@"查看信息"])
    {
        TabBarController *tabbar=[TabBarController new];
        tabbar.selectedIndex=1;
        self.window.rootViewController=tabbar;
    }
    else if ([shortcutItem.localizedTitle isEqual:@"购买商城"])
    {
        TabBarController *tabbar=[TabBarController new];
        tabbar.selectedIndex=2;
        self.window.rootViewController=tabbar;
    }
}
@end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容