iOS 3D touch 使用技巧
第一个 在桌面中3d Touch 打开菜单

由于本人纯属代码党,本次实现方法也只使用代码实现
到达到这个效果并不难,只需要在appdelegate中实现以下代码即可 ,当然也有缺点,就是这个app没运行过的话是用不了3dtouch呼出菜单
- (void)setting3DTouchModule{
// 判断系统版本大于9.0再设置 (若不判断 在低版本系统中会崩溃)
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0){
// 自定义图标
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"图片名称"];
UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"item类型1" localizedTitle:@"item标题1" localizedSubtitle:@"子标题1" icon:icon1 userInfo:nil];
UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"item类型2" localizedTitle:@"item标题2" localizedSubtitle:@"子标题2" icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeCompose] userInfo:nil];
// item 数组
NSArray *shortItems = [[NSArray alloc] initWithObjects: shortItem1,shortItem2, nil];
// 设置按钮
[[UIApplication sharedApplication] setShortcutItems:shortItems];
}
}
// 通过3dtouch菜单启动 后回调
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
// 可以通过标题 字符串判断 来确认 是哪个item
if ([shortcutItem.localizedTitle isEqualToString: @"item标题1"]){
}
}
在 didFinishLaunchingWithOptions方法中执行
[self setting3DTouchModule];
即可
第二种效果 触发机制 参考 微信朋友圈 3dtouch打开图片

这个由于涉及到tableview /collectionview中cell的重用机制(如果你只给某个view加入 3dtouch手势的话可以无视), 需要对cell做一定的自定义操作
我这里以collectionview为例,在回调cell 的方法里,将当前controller对象传入cell中进行 3DTouch事件注册
而正常添加3dtouch只需要下面这一句代码
[self registerForPreviewingWithDelegate:self sourceView:cell.contentView]; //正常添加3DTouch事件
添加3DTouch的controller 要遵循UIViewControllerPreviewingDelegate协议
然后实现 两个代理方法
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{
// 打开详情页触发
if (viewControllerToCommit){
[self showViewController:viewControllerToCommit sender:self];
}
}
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
// 这里要返回要打开的viewController
return nil;
}
具体实现 可以参考我的demo
再者就是下面的按钮

加入购物车 这个按钮是需要我们在 回调的那个controller中实现以下代码
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems{
UIPreviewAction *itemA = [UIPreviewAction actionWithTitle:@"加入购物车" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"你要做的操作");
}];
return @[itemA];
}
具体请参考demo
http://files.cnblogs.com/files/n1ckyxu/IOS_3DTouch_Demo.zip
iOS 3D touch 使用技巧的更多相关文章
- iOS 3D Touch 适配开发
3D Touch的主要应用 文档给出的应用介绍主要有两块: 1.A user can now press your Home screen icon to immediately access fun ...
- iOS 3D Touch功能 3 -备
新的触摸体验——iOS9的3D Touch 一.引言 二.在模拟器上学习和测试3D Touch 附.SBShortcutMenuSimulator的安装和使用 三.3D Touch的主要应用 四.3D ...
- iOS 3D Touch功能
新的触摸体验——iOS9的3D Touch 一.引言 在iphone6s问世之后,很多果粉都争先要体验3D Touch给用户带来的额外维度上的交互,这个设计之所以叫做3D Touch,其原理上是增加了 ...
- 3D Touch开发技巧的笔记
iPhone6s以及iPhone6s plus搭载iOS9,有一个新功能叫做3D Touch,这个功能有很大的用处,关键是要会用,这给交互方式又多了一个新的选择和思考,比如说游戏中的额外控制选项.绘图 ...
- iOS 3D Touch实践
本文主要讲解3DTouch各种场景下的开发方法,开发主屏幕应用icon上的快捷选项标签(Home Screen Quick Actions),静态设置 UIApplicationShortcutIte ...
- ios 3D Touch功能的实现
ios9中3D Touch功能是一个新的亮点,这个方便快捷的功能实现也比较简单,废话不多说直接上代码, 一.3D Touch功能添加分为两种(1).静态标签 (2).动态标签 (1).静态添加 这个方 ...
- 关于iOS 3D touch 指纹验证的随笔
file:///Users/OWen/Desktop/3DTouch.png 随着iOS系统不断的更新迭代,苹果总会推出一些新的功能,今天就研究了一下iOS8之后推出的指纹验证的功能,然后写了一个小d ...
- 3D Touch开发全面教程之Peek and Pop - 预览和弹出
## 3D Touch开发全面教程之Peek and Pop - 预览和弹出 --- ### 了解3D Touch 在iPhone 6s和iPhone 6s Plus中Apple引入了3D Touch ...
- 在iOS9 中使用3D Touch
iOS9提供了四类API( Home Screen Quick Action . UIKit Peek & Pop . WebView Peek & Pop 和 UITouch For ...
随机推荐
- Postman - HTTP接口测试工具
Postman 是一个 Chrome 的 插件,它主要是用来模拟各种HTTP请求的(如:get/post/delete/put..等等),下面介绍下Postman的安装和使用方法: 一.安装Postm ...
- angularjs指令(二)
最近学习了下angularjs指令的相关知识,也参考了前人的一些文章,在此总结下. 欢迎批评指出错误的地方. Angularjs指令定义的API AngularJs的指令定义大致如下 angula ...
- BestCoder#16 A-Revenge of Segment Tree
Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...
- js函数中参数的传递
数据类型 在 javascript 中数据类型可以分为两类: 基本类型值 primitive type,比如Undefined,Null,Boolean,Number,String. 引用类型值,也就 ...
- 推荐两款PC健康小软件
一.前言 对于经常需要坐在电脑前工作一整天的人来说,健康问题是不得不关注的.下面推荐我一直在用的两款体积非常小(几百KB)的健康小软件,也许可以在无形中保护你.提醒你. 1. FadeTop 这是一款 ...
- ajax与HTML5 history pushState/replaceState实例
一.本文就是个实例展示 三点: 我就TM想找个例子,知道如何个使用,使用语法什么的滚粗 跟搜索引擎搞基 自己备忘 精力总是有限的,昨天一冲动,在上海浦东外环之外订了个90米的房子,要借钱筹首付.贷款和 ...
- NOIP欢乐模拟赛 T1 解题报告
小澳的方阵 (matrix.cpp/c/pas) [题目描述] 小澳最近迷上了考古,他发现秦始皇的兵马俑布局十分有特点,热爱钻研的小澳打算在电脑上还原这个伟大的布局. 他努力钻研,发现秦始皇布置兵马俑 ...
- 【JAVA】JMX简单使用方法
[BEAN] 配置 <!-- JMX 对应的接口服务--> <bean id="emailInterfaceServer" class="com.s ...
- SQL 学习笔记
1.判断数据库中某个值是否为null(而不是'null',空字符串'',若干个空格' ') 一定不能用=null 或 !=null,而要用is null 或 is not null. 2.在sqlse ...
- filter,orderBy等过滤器
filter用法比较灵活(也增加了较高的复杂度),单独列出. 基本的用法: <input type="text" class="search" ng-mo ...