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. ...
随机推荐
- codevs1002搭桥(prim)
题目描述: 这是道题题意有点迷(或者是我语文不好),但其实实际上求的就是图中连通块的个数,然后在连通块与连通块之间连边建图跑最小生成树.但是--这个图可能是不连通的--求桥的数量和总长 于是我立刻想到 ...
- Zabbix概念、安装以及快速入门
Zabbix is an enterprise-class open source distributed monitoring solution.[1] Zabbix是一个企业级的.开源的.分布式的 ...
- 网站URL重写(Java UrlRewrite 的使用)
现在大部分的网站和商城都会使用到URL重写,接触到这个,也是因为正在做的电子商务商城.URL重写,是将原有的URL采用另一种规则来显示,使得用户方便访问同时也屏蔽一些信息. 在此说下它的好处,在开发过 ...
- 中文版的jqGrid实例大全
中文版的jqGrid实例大全 http://blog.mn886.net/jqGrid/
- NGINX----源码阅读---cycle
/* * Copyright (C) Igor Sysoev * Copyright (C) Nginx, Inc. */ #ifndef _NGX_CYCLE_H_INCLUDED_#define ...
- matcaffe的blob维度顺序
matcaffe是caffe的matlab接口.caffe本身是C++写的,其blob的维度顺序是[N,C,H,W],N表示batchSize,C表示channel数目,H表示feature map的 ...
- JDK根目录介绍
/bin 存放可执行程序(编译器javac.exe 运行器java.exe 文档生成器javadoc.exe等 ). /db 小型数据库文件. /jre JRE. /include 形成jdk的c. ...
- IOS常遇问题个人收藏网址指南
代码适配Masonry使用的详细介绍: http://blog.csdn.net/majiakun1/article/details/51160339 Masonry使用注意篇: http://www ...
- webkit框架的使用
// // JSViewController.m // Library // // Created by 朱逸 on 16/7/7. // Copyright © 2016年 朱逸. All righ ...
- 给go添加各种package
go version 1.1.2 For example you need to install the webscoket pakeage try go get code.goo ...