1. 3D-Touch简单介绍

  3D-Touch是iPhone 6s推出的一种可以让你与手机进行互动的全新方式。这一次,iPhone 能够感应你按压屏幕的力度。除了轻点、轻扫、双指开合这些熟悉的 Multi‑Touch 手势之外,3D Touch 还带来 Peek 和 Pop,为 iPhone 的使用体验开拓出全新的维度。而且,当你使用 3D Touch 时,iPhone 将回以轻微的触感,让你不仅能够看到按下屏幕的操作效果,还能感觉得到。

  3D-Touch含有3种feature功能,压力感应(Press Sensitivity)、Peek和Pop手势、快捷方式(Quick Actions)

2. 如果让模拟器支持3D-Touch

   目前官方文档还不支持3d-touch,可以借助github的开源项目,SBShortcutMenuSimulator(点击下载).

安装和使用也比较简单

  1. 安装 

    git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.git
    cd SBShortcutMenuSimulator
    make
  2. 安装完,在SBShortcutMenuSimulator的目录执行以下方法
    xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard --environment DYLD_INSERT_LIBRARIES=$PWD/SBShortcutMenuSimulator.dylib
    xcrun simctl spawn booted launchctl stop com.apple.SpringBoard
  3. 使用
    // 'com.x.x' 为程序的bundle id, id可以随便指定
    echo 'com.xxx.xxx' | nc 127.0.0.1

3. Quick Actions2种适配方法

  1. 静态定义

    静态定义常用的key:

UIApplicationShortcutItemType     //(必须使用) 用来区分与其他快速选项的分类
UIApplicationShortcutItemTitle   //(必须使用) 快速选项显示的标题
UIApplicationShortcutItemSubtitle // 快速选项显示的子标题
UIApplicationShortcutItemIconType // 图片类型由系统提供,大约提供了29种
UIApplicationShortcutItemIconFile // 自定义的图标
UIApplicationShortcutItemUserInfo // 附加信息(NSDictionary)

     静态设置在Info.plist文件中定义

<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeBookmark</string>
<key>UIApplicationShortcutItemTitle</key>
<string>打开最后阅读的书籍</string>
<key>UIApplicationShortcutItemType</key>
<string>3dTouchOpenBookItem</string>
<key>UIApplicationShortcutItemUserInfo</key>
<dict>
<key>shorcutKey</key>
<string>shorcutValue</string>
</dict>
</dict>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeSearch</string>
<key>UIApplicationShortcutItemTitle</key>
<string>搜索书架</string>
<key>UIApplicationShortcutItemType</key>
<string>3dTouchSearchItem</string>
</dict>

      <dict>
        <key>UIApplicationShortcutItemIconFile</key>
        <string>dl_d.png</string>
        <key>UIApplicationShortcutItemTitle</key>
        <string>热门活动</string>
        <key>UIApplicationShortcutItemType</key>
        <string>QuickActionActivityItem</string>
      </dict>

    </array>

  ps : 如果使用 UIApplicationShortcutItemIconFile, UIApplicationShortcuIconType将不起作用,使用参考上面红色字体的地址

  2. 动态定义

- (void)initApplication3DTouch:(UIApplication *)application {

    NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
[userInfo setObject:@"哈哈" forKey:@"haha"];
// 自定义获取本地的图片并传递一些参数
UIMutableApplicationShortcutItem *itemTest = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"标题" localizedSubtitle:@"副标题" icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"本地图片"] userInfo:userInfo]; // 打开最后阅读的一本书
UIApplicationShortcutIcon *openBook = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeBookmark];
UIMutableApplicationShortcutItem *itemOpenBook = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"打开最后阅读的书籍"];
itemOpenBook.icon = openBook; // 找书
UIApplicationShortcutIcon *searchBook = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeSearch];
UIMutableApplicationShortcutItem *itemSearchBook = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"搜索书架"];
itemSearchBook.icon = searchBook; //
application.shortcutItems = @[itemTest, itemOpenBook, itemSearchBook];
}

  

  3. 响应Quick Actions事件

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {

    if ([shortcutItem.type isEqualToString:@""]) {
NSLog(@"搜索书架");
} else if ([shortcutItem.type isEqualToString:@""]) {
NSDictionary *dict = shortcutItem.userInfo;
NSLog(@"dict为传递过来的参数");
}
}

3. 备注

  1. 快捷标签最多可以创建四个,包括静态的和动态的. 静态的会显示在动态的前面

  2. 静态的可以在程序不打开的情况下显示,动态的不可以

  3. 关于如何动态的移除动态添加的Quick Actions   

application.shortcutItems = nil; // 尝试了一下,可以通过这个方式把动态quick action移除

  如果你不是在wb145230博客园看到本文,请点击查看原文.

3D-Touch Home Screen Quick Actions 使用的更多相关文章

  1. iOS9 3DTouch 之 Home Screen Quick Actions

    最后更新:2016-12-18 测试环境: Xcode8.1 一.前言 iOS9 已经过去一年了,3D Touch也在项目中实战过,但一直没有总结一下,现在新的项目也用到了3D Touch, 网上找了 ...

  2. iOS 3D Touch实践

    本文主要讲解3DTouch各种场景下的开发方法,开发主屏幕应用icon上的快捷选项标签(Home Screen Quick Actions),静态设置 UIApplicationShortcutIte ...

  3. 初学3D Touch

    引言 With iOS 9, new iPhone models add a third dimension to the user interface. A user can now press y ...

  4. iOS 3D Touch 适配开发

    3D Touch的主要应用 文档给出的应用介绍主要有两块: 1.A user can now press your Home screen icon to immediately access fun ...

  5. 【iOS】3D Touch

    文章内容来源于Apple的开发者文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptu ...

  6. 3d touch 应用 2 -备用

    一.引言 在iphone6s问世之后,很多果粉都争先要体验3D Touch给用户带来的额外维度上的交互,这个设计之所以叫做3D Touch,其原理上是增加了一个压力的感触,通过区分轻按和重按来进行不同 ...

  7. iOS 3D Touch功能 3 -备

    新的触摸体验——iOS9的3D Touch 一.引言 二.在模拟器上学习和测试3D Touch 附.SBShortcutMenuSimulator的安装和使用 三.3D Touch的主要应用 四.3D ...

  8. iOS 9之3D Touch

    金田 北京时间9月10日凌晨, Apple在美国旧金山比尔格拉汉姆公民大礼堂(Bill Graham Civic Auditorium)召开新品发布会.本次着重介绍了3D Touch功能, 大体介绍一 ...

  9. iOS9新特性-3D Touch

    本文主要讲解3DTouch各种场景下的开发方法,开发主屏幕应用icon上的快捷选项标签(Home Screen Quick Actions),静态设置 UIApplicationShortcutIte ...

随机推荐

  1. 百度UEditor图片上传、SpringMVC、Freemarker、Tomcat、Nginx、静态资源

    个人官网.公司项目都需要 可视化编辑器,百度UEditor做得很不错,就用的这个.项目后台用到了SpringMVC.Freemarker,开发过程中部署在Jetty,线上部署用Tomcat,最后可能配 ...

  2. Android中密码输入内容可见性切换

    今天在做项目的时候遇到了一个关于密码输入框可见性切换问题,上网搜了搜,这里面门道还不小,做一个记录吧,下次遇到就好解决了. 首先写了一个简单的测试工程: <LinearLayout xmlns: ...

  3. 【CF706C】Hard problem

    Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve h ...

  4. [NPM] Use custom config settings in your npm scripts

    In addition to package.json level variables (such as name and version), you can have custom conf set ...

  5. 测试与 debug 心得

    测试不等同于调试,各自都有自己的概念集和方法论. Test:examine input/output pairs. 调试:定位,修改. 但如果能做到错误异常的准确定位,调试的一半以上的工作已经完成了. ...

  6. 【dotnet跨平台】Asp.net 正在经历的变革

     [dotnet跨平台]Asp.net 正在经历的变革 Asp.net 正在经历一场变革.从官网:https://get.asp.net/ 我们能够看到多个版本号的字眼例如以下: ASP.NET ...

  7. FMDB数据库框架

    nFMDB   nFMDB n什么是FMDB pFMDB是iOS平台的SQLite数据库框架 pFMDB以OC的方式封装了SQLite的C语言API p nFMDB的优点 p使用起来更加面向对象,省去 ...

  8. 建立一个OTP应用

    http://www.javaeye.com/topic/374167 以下是在erlang项目开发中的一些记录,即包含很多通俗易懂的原则,也包含一些似是而非的建议,比较混乱,还没有积累到一个可以分门 ...

  9. svn创建版本库和删除版本库

    作者:朱金灿 来源:http://blog.csdn.net/clever101 svn创建版本库的做法:使用cd命令进入版本仓库的根目录,我的是E:\Repository,然后运行命令: svnad ...

  10. Vue中this的绑定

    之前写过一篇文章 ES6与React中this完全解惑 其实Vue也是相同的道理.在Vue的官方文档中提到: 不要在选项属性或回调上使用箭头函数,比如 created: () => consol ...