3DTouch.png
iPhone6s
和iPhone6sPlus
上市了,很多朋友拿到新機(jī)后第一個(gè)想體驗(yàn)的就是它的3DTouch
了。我同事正好買了個(gè)iphone6s
,簡(jiǎn)單體驗(yàn)下了3DTouch
,感覺(jué)不好按出來(lái)的,可能習(xí)慣了就好多了。有了新技術(shù),對(duì)于程序員的我研究下3DTouch的技術(shù),正好有同事的
iphone6s
可以測(cè)試。下面直接上代碼:
創(chuàng)建應(yīng)用ICON上的UIApplicationShortcutIcon
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"TabBar_HomeSelected"];
//有圖標(biāo)
UIApplicationShortcutItem *shortItem0 = [[UIApplicationShortcutItem alloc] initWithType:@"test" localizedTitle:@"hello" localizedSubtitle:@"hello world" icon:icon userInfo:@{@"":@""}];
//沒(méi)圖標(biāo)
UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"open" localizedTitle:@"open"];
UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"alert" localizedTitle:@"alert"];
NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem0,shortItem1, shortItem2, nil];
[[UIApplication sharedApplication] setShortcutItems:shortItems];
return YES;
}
效果圖如下:
效果圖1.jpeg
點(diǎn)擊的代理方法
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
if ([shortcutItem.localizedTitle isEqual: @"alert"]) {
//todo do some thing
return;
}
}
PS
demo地址,請(qǐng)猛戳這里。