3DTouch--2
苹果太贱了! 3D Touch 只能在真机上面试,模拟器没办法玩!
-------------
描述有点粗燥。。。。。有6S 在手上玩得童鞋会更加清楚,只有玩过才更加体验到。
首先 有几个要知道的手势
第一, 在点击app icon 的手长按 并且用力一点(用点力不然没效果,不会弄坏手机,坏了也不是我的,哈哈!) 就会出现 几个Item。
第二,(1)在app 里面 长按 也要用力往下压 跟着就会可以弹出 自定义的 ViewController。这个时候如果你放手了那么就会消失。
(2)如果 长按 往下压 弹出了自定义的ViewController 之后跟着网上移动,就可以出现 选择Action。
第三,如果 长按 往下压 弹出了自定义的ViewController,然后更加 用力一点 比 弹出的ViewController的力度 更加大一点 那么 自定义的这个ViewController 就会 相当于push 进来了。
首先来一个获取版本号,因为3D Touch 只有在iOS9 才会有,在后面演示的代码就不上这个判断。
- #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
首先在 - (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions 去创建 item ,这几个item 就是在点击icon 的时候出现的.
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- [self createItem];
- UIApplicationShortcutItem *item = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];
- if (item)
- {
- NSLog(@"We've launched from shortcut item: %@", item.localizedTitle);
- }
- else
- {
- NSLog(@"We've launched properly.");
- }
- return YES;
- }
- - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
- // react to shortcut item selections
- NSLog(@"A shortcut item was pressed. It was %@.", shortcutItem.localizedTitle);
- }
创建item 可以在plist 里面定义,也可以用代码去写。可以带icon 也可以不带icon。
至于有些app 在 touch 之后显示的icon 在左边或者右边,其实这个是跟你的app 放在你手机的位置有关系,这个iOS 自动处理掉。
- -(void) createItem
- {
- //自定义icon 的初始化方法
- // UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"your_icon"];
- // UIMutableApplicationShortcutItem *item0 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.your.helloWorld" localizedTitle:@"Title" localizedSubtitle:@"sub Title" icon:icon1 userInfo:nil];
- //这种是随意没有icon 的
- UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"test.com.A" localizedTitle:@"三条A"];
- UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"test.com.B" localizedTitle:@"三条B"];
- UIMutableApplicationShortcutItem *item3 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"test.com.C" localizedTitle:@"三条C"];
- NSArray *addArr = @[item2,item3,item1];
- //为什么这两句话可以不用,因为我们可以在plist 里面 加入 UIApplicationShortcutItems
- // NSArray *existArr = [UIApplication sharedApplication].shortcutItems;
- // [UIApplication sharedApplication].shortcutItems = [existArr arrayByAddingObjectsFromArray:addArr];
- [UIApplication sharedApplication].shortcutItems = addArr;
- }
--------------------------------------------------------------------------
分割线----------------------------------------------------------
接着这里要说的是 在 长按touch ViewController 弹出 自定义的ViewContoller
首先 在 ViewController.m 里面加入(这个就是要手指 长按并且要往下压的ViewController)
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- //首先要判断一下 压力感是否有效,跟着注册delegate
- [self check3DTouch];
- }
- - (void)check3DTouch
- {
- // register for 3D Touch (if available)
- if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
- {
- [self registerForPreviewingWithDelegate:self sourceView:self.view];
- NSLog(@"3D Touch 可用!");
- }
- else
- {
- NSLog(@"3D Touch 无效");
- }
- }
再写上你想要 弹出的ViewController
- - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
- {
- // check if we're not already displaying a preview controller
- //SecViewController 是要弹出悬浮展示的ViewController
- if ([self.presentedViewController isKindOfClass:[SecViewController class]]) {
- return nil;
- }
- SecViewController *sec = [[SecViewController alloc] init];
- return sec;
- }
未了方便的演示 我们在 SecViewController 里面加上一个返回的手势
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissMe)];
- [self.view addGestureRecognizer:tap];
- - (void)dismissMe{
- // dismiss this view controller
- [self dismissViewControllerAnimated:YES completion:nil];
- }
当弹出自定义的SecViewController 之后 然后我们往上移动那么就会出现Action
这代码是写在SecViewController 里面的
- - (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
- // setup a list of preview actions
- UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"这里可以做你想要做的事情的Aciton" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
- NSLog(@"click");
- }];
- // add them to an arrary
- //想要显示多个就定义多个 UIPreviewAction
- NSArray *actions = @[action1];
- // and return them (return the array of actions instead to see all items ungrouped)
- return actions;
- }
--------------------------------------------------------------------------
分割线----------------------------------------------------------
这个全屏展示方法(相当于push SecViewController) ,这个方法是要 更加给大点力度往下压的时候 才会出发的 这个方法写在ViewController 里面
- //这个方法是在什么时候出发呢?就是 给更加大的力度的时候进去 全屏状态
- - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
- // deep press: bring up the commit view controller (pop)
- [self showViewController:viewControllerToCommit sender:self];
- }
初次接触只有学习到这些东西了。。。
有新的东西后续补充
3DTouch--2的更多相关文章
- 3DTouch开发 (基础)
一.3DTouch开发准备工作(让模拟器也支持 3DTouch 的解决办法) 需要支持3DTouch的设备,如iPhone6s或以上.iOS9或以上.Xcode7或以上,估计很多和我一样的屌丝还没有i ...
- iOS - 3DTouch 3D 触摸
1.3DTouch 简介 3DTouch 是 iOS9 + 系统下,在 iPhone6s(iPhone6s Plus)+ 手机上才能够使用的功能. 1.1 3DTouch 基本类型 1.主屏幕快速选项 ...
- Xcode7中添加3DTouch
首先是插件SBShortcutMenuSimulator的安装 1.git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.g ...
- 3DTouch
3DTouch 一.主屏按压(Home Screen Quik Actions) 1.静态标签 在info.plist文件中新增项 关键字 意义 UIApplicationShortcutItems ...
- 使用UIImagePickerController时3DTouch引起的Crash问题的解决--备用
一.crash的场景 程序中用到UIImagePickerController时,如果在IPhone6S上运行APP,当forceTouch 一个图片时程序会crash,并附带如下crash mess ...
- 使用UIImagePickerController时3DTouch引起Crash
一.crash的场景 程序中用到UIImagePickerController时,如果在IPhone6S上运行APP,当forceTouch 一个图片时程序会crash,并附带如下crash mess ...
- 3DTouch简单了解
3D Touch的三大模块 代码Demo:https://github.com/haozheMa/3DTouch 在我们的app中使用3D Touch功能,主要分为以下三个模块: 1.Home Scr ...
- 配置Info.plist (设置状态栏样式、自定义定位时系统弹出的提示语、配置3DTouch应用快捷菜单)
一.概述 iOS中很多功能需要配置Info.plist才能实现,如设置后台运行.支持打开的文件类型.自定义访问隐私内容时弹出的提示等.了解Info.plist中各字段及其含义,可以访问苹果开发网站相关 ...
- 3DTouch - iOS新特性
概述 3DTouch是一种立体触控技术,被苹果称为新一代多点触控技术. 详细 代码下载:http://www.demodashi.com/demo/10708.html 6s和6s plus之后特有效 ...
- iOS 3DTouch
概述 iOS10系统登录中国,在系统中对3D Touch的使用需求更频繁,所以对iOS9中便引入的3D Touch功能做一些了解是很有必要的 详细 代码下载:http://www.demodashi. ...
随机推荐
- HDU ACM-Steps
HDU ACM-Steps RECORD Chapter 1 Section 1 暖手题 1.1.1 A+B for Input-Output Practice (I) #include <st ...
- [转]解决VS2008 开发Windows Mobile 项目生成速度慢的问题
最近用VS2008开发Windows Mobile程序,使用C#..NET Compact Framework,发现项目生成速度比较慢.用VS2008打开项目后,开始一段时间生成速度还能忍受,时间一长 ...
- 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群(转载-2)
原文:http://www.cnblogs.com/PurpleDream/p/4510279.html 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群 前言: ...
- Hibernate5-课程笔记4
单表查询: Hibernate是DAO层技术,对数据的使用,查询是最为重要的.Hibernate的查询技术非常强大,支持原始SQL语句查询,支持QBC查询及Hibernate特有的HQL查询. H ...
- 利用java实现抽奖转盘(着重安全控制)
本文是针对jquery 实现抽奖转盘作者的一个补充(主要用java去实现转盘结果生成及存储,解决jquery 做法 非法用户采用模拟器实现改变转盘值的风险性),针对jQuery的具体实现,请看案例:h ...
- linux内核之链表操作解析
本文只是对linux内核中的链表进行分析.内核版本是linux-2.6.32.63.文件在:linux内核/linux-2.6.32.63/include/linux/list.h.本文对list.h ...
- Struts2的DMI跟SMI
我使用的Struts2的版本是2.5.2,今天在使用Struts2的DMI(动态方法调用)的时候出现了一个有趣的问题,我先把我的配置及代码展示一下: web.xml <filter> &l ...
- ASP.NET 企业组织机构代码验证
/// <summary> /// 组织机构代码验证 /// </summary> /// <param name="arg"></par ...
- 【卷二】网络二—TCP服务器与客户端
经过上回简单地介绍,大家对服务器多少应该清楚一些了吧!还记得TCP: (Transmission Control Protocol) 传输控制协议? 还记得IP: (Internet Protocol ...
- reinterpret_cast应用
reinterpret_cast 的一个实际用途是在哈希函数中,即,通过让两个不同的值几乎不以相同的索引结尾的方式将值映射到索引. #include <iostream> using na ...