新的触摸体验——iOS9的3D Touch
3DTouchTest.zip
代码部分
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#pragma mark 创建3dtouch标签
[self creatItems];
return YES;
}
#pragma mark 3dtouch触发方法
- (void)application:(UIApplication *)application
performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
completionHandler:(void(^)(BOOL succeeded))completionHandler {
NSLog(@"shortcutItem.type = %@",shortcutItem.type);
}
#pragma mark 3dtouch标签位置
-(void)creatItems {
#pragma mark 添加图片
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"TouchPro"];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"TouchOrder"];
UIApplicationShortcutIcon *icon3 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"TouchScan"];
UIApplicationShortcutIcon *icon4 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"TouchSignIn"];
#pragma mark 添加标签
UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"UITouchText.Product" localizedTitle:@"找产品" localizedSubtitle:nil icon:icon1 userInfo:nil];
UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"UITouchText.Order" localizedTitle:@"理订单" localizedSubtitle:nil icon:icon2 userInfo:nil];
UIMutableApplicationShortcutItem *item3 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"UITouchText.scan" localizedTitle:@"扫一扫" localizedSubtitle:nil icon:icon3 userInfo:nil];
UIMutableApplicationShortcutItem *item4 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"UITouchText.TodaySignIn" localizedTitle:@"每日签到" localizedSubtitle:nil icon:icon4 userInfo:nil];
#pragma mark 将所有的标签数组添加进去
NSArray *addArr = @[item4,item3,item2,item1];
[UIApplication sharedApplication].shortcutItems = addArr;
}