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. ...
随机推荐
- composer install 遇到问题 Problem 1 - phpunit/phpunit 5.7.5 requires php ^5.6 || ^7.0 -> your PHP version (5.5.3 0) does not satisfy that requirement.
$ composer install Loading composer repositories with package information Updating dependencies (inc ...
- jq 测试是否到页面最底端
$(window).scroll(function () { if ($(document).scrollTop() + $(window).height() >= $(document).he ...
- D3.js:交互式操作
用户用于交互的工具一般有三种:鼠标.键盘.触屏. 1. 添加交互 对某一元素添加交互操作十分简单,代码如下: //画布大小 var width = 500, height = 500; // 在bod ...
- angular1 实现页面切换及tag页面
tag页面实现<div class="b_gray" style="padding-left:24px;border-bottom:1px solid #ccc&q ...
- SDN基础
http://www.h3c.com.cn/Solution/Smart_Network/SDN/ http://network.51cto.com/network/content2013/SDNke ...
- NoSQL数据建模技术
原文来自“NoSQL Data Modeling Techniques”,由酷壳网陈皓编译<NoSQL数据建模技术>.这篇文章看完之后,你可能会对NoSQL的数据结构会有些感觉.我的感觉是 ...
- java学习笔记:反射
1.什么是反射? Reflection(反射)是被视为动态语言的关键,反射机制允许程序做执行期间借助于ReflectionAPI取得任何类的内部信息,并能直接操作任意对象内部属性及方法 2.反射相关的 ...
- springIOC
从这段代码开始 ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); Pers ...
- js---疑点代码段解析
function count() { var arr = []; for (var i=1; i<=3; i++) { console.log("iii---"+i); ar ...
- Java的URL来下载网页源码
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; impor ...