iPhone6s
和iPhone6sPlus
上市了,很多朋友拿到新机后第一个想体验的就是它的3DTouch
了。我同事正好买了个iphone6s
,简单体验下了3DTouch
,感觉不好按出来的,可能习惯了就好多了。有了新技术,对于程序员的我研究下3DTouch的技术,正好有同事的
iphone6s
可以测试。下面直接上代码:
创建应用ICON上的UIApplicationShortcutIcon
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"TabBar_HomeSelected"];
//有图标
UIApplicationShortcutItem *shortItem0 = [[UIApplicationShortcutItem alloc] initWithType:@"test" localizedTitle:@"hello" localizedSubtitle:@"hello world" icon:icon userInfo:@{@"":@""}];
//没图标
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
点击的代理方法
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
if ([shortcutItem.localizedTitle isEqual: @"alert"]) {
//todo do some thing
return;
}
}
PS
demo地址,请猛戳这里。
网友评论