IOS9新特性-3DTouch开发

3DTouch.png

iPhone6siPhone6sPlus上市了,很多朋友拿到新机后第一个想体验的就是它的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地址,请猛戳这里

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容