iOS 3DTouch 代码实现

- (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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值