iOS 3DTouch 代码实现

来源:互联网 发布:et200proprofinet网络 编辑:程序博客网 时间:2024/05/23 01:11

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    /**     *  @author 李凯利, 16-10-19 11:10:30     *     *  UIApplicationShortcutIcon :设置每个item项目的图标 可以是系统的也可以是自定义图标,此类提供两个初始化方法来供我们选择:iconWithType:方法设置系统图标     iconWithTemplatelmageName:方法设置自定义图标          UIApplicationShortcutItem类中的属性:      type:标识每一个Item项目,通过标识我们可以区分点击相应每一项该触发哪些操作(在3Dtouchu的代理方法中就是靠type 属性来区分点击的那一项)        localizedTitle:每一个item 的标题     localizedSubtitle:每个item的副标题 可有可无     icon:每个item对应的图标     userInfo:属性的信息字典,用于传值     */    //栏目一    UIApplicationShortcutIcon * icon1 =[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose];    UIApplicationShortcutItem* item1 =[[UIApplicationShortcutItem alloc]initWithType:@"item1" localizedTitle:@"入口1" localizedSubtitle:@"入口1副标题" icon:icon1 userInfo:nil];    //栏目二    UIApplicationShortcutIcon * icon2 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePlay];    UIApplicationShortcutItem * item2 =[[UIApplicationShortcutItem alloc]initWithType:@"item2" localizedTitle:@"入口二" localizedSubtitle:@"入口二副标题" icon:icon2 userInfo:nil];    //栏目3    UIApplicationShortcutIcon *icon3 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePause];    UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItem alloc] initWithType:@"item3" localizedTitle:@"入口3" localizedSubtitle:@"入口3副标题" icon:icon3 userInfo:nil];        //栏目4    UIApplicationShortcutIcon *icon4 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];    UIApplicationShortcutItem *item4 = [[UIApplicationShortcutItem alloc] initWithType:@"item4" localizedTitle:@"入口4" localizedSubtitle:@"入口4副标题" icon:icon4 userInfo:nil];    //设置shortcutItems 需要注意的是shortcutItems 数组最多只能加入四个item,超过四个只会显示前面的四个    application.shortcutItems = @[item1,item2,item3,item4];        return YES;}#pragma mark ----3DTouchu的代理方法-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{    //根据item对应的type标识处理对应的点击操作    NSString * itemType = shortcutItem.type;    if ([@"item1" isEqualToString:itemType]) {        NSLog(@"item1");    }    else if ([@"item2" isEqualToString:itemType]){        NSLog(@"item2");    }    else if ([@"item3" isEqualToString:itemType]){        NSLog(@"item3");    }    else if ([@"item4" isEqualToString:itemType]){        NSLog(@"item4");    }    }

0 0
原创粉丝点击