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. jsvc 启动java 在linux下的实现原理

    http://blog.csdn.net/raintungli/article/details/8265009 JSVC:http://commons.apache.org/proper/common ...

  2. http://lists.mysql.com/mysql

    http://lists.mysql.com/mysql http://www.ehowstuff.com/how-to-fix-mysql-database-error-cant-create-da ...

  3. [Grid Layout] Place grid items on a grid using grid-column and grid-row

    It’s possible to position a grid item anywhere on a grid track. To do this, let’s specify some grid- ...

  4. lipo: can't open input file

    错误1: /Volumes/Mac OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/u ...

  5. 电子商务系统的设计与实现(十):DWZ框架与第三方分页组件整合

    晚上,就是刚刚,在后端管理系统中使用DWZ框架. 先是,直接使用官网网站的Demo,dwz-jui,与编程语言无关的纯静态的那个原始项目. 很快就搭建好了左侧菜单,打开菜单后,出现Tab页面,然后显示 ...

  6. 【BZOJ 1022】 [SHOI2008]小约翰的游戏John

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1022 [题意] [题解] 和这题类似http://blog.csdn.net/harl ...

  7. radio选择事件 onchange事件 onclick事件

    单选框按钮(radio)选择事件怎么设置呢? 既可以在radio标签里设置onclick事件实现,也可以设置它的onchange事件实现,效果一样,代码如下: <input id="r ...

  8. oracle表空间查询维护命令大全之中的一个(数据表空间)史上最全

          表空间是数据库的逻辑划分,一个表空间仅仅能属于一个数据库. 全部的数据库对象都存放在建立指定的表空间中.但主要存放的是表, 所以称作表空间.在oracle 数据库中至少存在一个表空间.即S ...

  9. 一起学Python:网络通信过程

    1. 2台电脑的网络 image 说明 如果两台电脑之间通过网线连接是可以直接通信的,但是需要提前设置好ip地址以及网络掩码 并且ip地址需要控制在同一网段内,例如 一台为192.168.1.1另一台 ...

  10. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...