OC - 3D Touch(1)
来源:互联网 发布:微信刷票软件开发 编辑:程序博客网 时间:2024/05/04 10:05
3D Touch 是 iPhone6S 上独有的一个功能,在屏幕下方增加了压力感应,从而可以检测平时手指按压屏幕的力度,然后系统可以识别到压力强度,再给出相应的选项。效果类似于以下:
创建按钮的方式有两种,一种是代码方式,一种是Info.plist
Info.plist:
实现代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // 判断系统版本,如果系统版本大于等于9.0,可以设置3D Touch if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0){ // 自定义图标 UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"图片名称"]; //定义type,标题,子标题,图片 UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"类型1" localizedTitle:@"标题1" localizedSubtitle:@"子标题1" icon:icon1 userInfo:nil]; //定义type,标题,子标题,图片 UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"类型2" localizedTitle:@"标题2" localizedSubtitle:@"子标题2" icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeCompose] userInfo:nil]; //定义type,标题,子标题,图片 UIApplicationShortcutItem *shortItem3 = [[UIApplicationShortcutItem alloc] initWithType:@"类型3" localizedTitle:@"标题3" localizedSubtitle:@"子标题3" icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeLocation] userInfo:nil]; // item 数组 NSArray *shortItems = [[NSArray alloc] initWithObjects: shortItem1,shortItem2, shortItem3,nil]; NSArray *existingItems = [UIApplication sharedApplication].shortcutItems; NSArray *updatedItems = [existingItems arrayByAddingObjectsFromArray:shortItems]; // 设置按钮 [UIApplication sharedApplication].shortcutItems = updatedItems; } self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; ViewController *vc = [[ViewController alloc]init]; UINavigationController *naviVc = [[UINavigationController alloc]initWithRootViewController:vc]; self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = naviVc; [self.window makeKeyAndVisible]; return YES;}
当点击标题按钮后就会触发3D Touch代理方法,设置自定义的跳转
#pragma mark-3DTouch添加的代理方法-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{ //判断设定的唯一标识,当选择 if ([shortcutItem.type isEqualToString:@"类型1"]) { My3DTouchViewController *vc = [[My3DTouchViewController alloc]init]; self.window.rootViewController = vc; } if ([shortcutItem.localizedTitle isEqualToString:@"标题1"]) { } if ([shortcutItem.localizedTitle isEqualToString:@"标题1"]) { }}
1 0
- OC - 3D Touch(1)
- OC - 3D Touch(2)
- iOS 3D touch OC代码
- 浅谈3D Touch(1) -- Home screen quick action
- 关于3D Touch
- 关于3D Touch
- 3D Touch初探
- 3D Touch大法
- 3D Touch
- ios 3D Touch
- 3D touch
- 3D Touch
- 3D Touch
- iphone 3D Touch
- 3D Touch入门
- 3D Touch APIs
- ios9 3D Touch
- 3D Touch详解
- Oracle外键不加索引会引起死锁问题
- CABasicAnimation的基本使用方法(移动·旋转·放大·缩小)
- 物理小词典
- 开动了
- AChartEngine折线图实例
- OC - 3D Touch(1)
- 发送邮件
- No handlers could be found for logger “apscheduler.scheduler”
- 123.View the Exhibits and examine the structures of the PRODUCTS, SALES, and CUSTOMERS
- Improve Magento Cache and Session by Using Redis
- Storm新特性之Flux
- 判断字符串是否回文
- Objective-C用正则表达式判断字符串是否为手机号、邮箱、身份证号
- HDFS小文件问题及解决方案