iOS-3D touch相关开发
2016-03-23 19:05
656 查看
3D Touch,就是屏幕可感应不同的感压力度触控,有Peek Pop 两种新手势。 6s出来的时候,我对这增加的新功能激动不已 ~ ~ 想着新技术,新玩意,App会越来越好的 ~ ~
3D Touch目前实现的功能,该实现的也实现了。现在把之前自己写项目的相关代码检出来供大家参考。
写在前面
是从iOS 9之后的系统支持的,UIViewController的.h文件中是这样地:
// Registers a view controller to participate with 3D Touch preview (peek) and commit (pop). - (id <UIViewControllerPreviewing>)registerForPreviewingWithDelegate:(id<UIViewControllerPreviewingDelegate>)delegate sourceView:(UIView *)sourceView NS_AVAILABLE_IOS(9_0); - (void)unregisterForPreviewingWithContext:(id <UIViewControllerPreviewing>)previewing NS_AVAILABLE_IOS(9_0);
so,注册前判断下系统还是相当有必要的,判断的宏定义我也给搞出来,哈哈
#define SC_IOS9 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) if (SC_IOS9) { //注册 if (SC_IOS9) { //注册 [self registerForPreviewingWithDelegate:self sourceView:mealsHistoryTableView];; }
第一弹: 快捷图标进入App
第一步:给快捷入口增加两个item
if (SC_IOS9) { //注册 [self threeDTouchForQuickOpenTheAppWithApplication:application]; }
#pragma mark - 3D图标快捷功能进入 /** * 3Dtouch快捷进入图标 * * @param application 当前程序 */ -(void)threeDTouchForQuickOpenTheAppWithApplication:(UIApplication *)application{ //第一个设置图标img UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"chatShowCal"]; //创建第一个快捷入口 UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc]initWithType:noti_3dtouch_chatWithShowCal localizedTitle:@"咨询瘦咖" localizedSubtitle:nil icon:icon1 userInfo:nil]; UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"camera"]; UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc]initWithType:noti_3dtouch_takePhotoOfFood localizedTitle:@"拍照上传" localizedSubtitle:nil icon:icon2 userInfo:nil]; //添加进去 application.shortcutItems = @[item1,item2]; }
第二步:响应该快捷入口,苹果提供的接收方法是:
// Called when the user activates your application by selecting a shortcut on the home screen, // except when -application:willFinishLaunchingWithOptions: or -application:didFinishLaunchingWithOptions returns NO. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED;
实现该方法 :
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler { //判断唯一标示 确定相对应的按钮 if([shortcutItem.type isEqualToString:noti_3dtouch_chatWithShowCal]){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:noti_3dtouch_chatWithShowCal object:nil]; }); } //判断唯一标示 确定相对应的按钮 if([shortcutItem.type isEqualToString:noti_3dtouch_takePhotoOfFood]){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:noti_3dtouch_takePhotoOfFood object:nil]; }); } }
OK,你可以搞下来试试了。效果如下,估计想也想到是什么效果了。。
第二弹:TableView实现Cell上的展示预览(peek)
,,随后见,饿的不行了,下班回家吃饭。
a4e0
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用中UISearchDisplayController搜索效果的用法
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- JavaScript数组函数unshift、shift、pop、push使用实例
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- JavaScript中pop()方法的使用教程