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. 【前端统计图】hcharts实现堆叠柱形图(与后台数据交互)

    原型图类似如下: 图片.png <!DOCTYPE > <html> <head> <meta charset="utf-8">&l ...

  2. 【76.83%】【codeforces 554A】Kyoya and Photobooks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. Http请求工具类(Java原生Form+Json)

    package com.tzx.cc.common.constant.util; import java.io.IOException; import java.io.InputStream; imp ...

  4. HTML中DOM核心知识有哪些(带实例超详解)

    HTML中DOM核心知识有哪些(带实例超详解) 一.总结: 1.先取html元素,然后再对他进行操作,取的话可以getElementById等 2.操作的话,可以是innerHtml,value等等 ...

  5. PHP的SPL标准库里面的堆(SplHeap)怎么使用

    PHP的SPL标准库里面的堆(SplHeap)怎么使用 一.总结 1.因为SplHeap是抽象类,所以要先继承,实现里面的抽象方法compare后,才能new对象使用. 二.PHP的SPL标准库里面的 ...

  6. 细说Oracle中NULL值

    1.NULL是什么? NULL表示UNKNOW(未知),其不代表不论什么值. 比如一行中某列没有不论什么值即为NULL. ORACLE同意不论什么一种数据类型的字段为空,除了下面两种情况: 1)主键字 ...

  7. python启动应用程序和终止应用程序

    python启动应用程序和终止应用程序 1. 目的 每天上班,工作需要,电脑上需要每天开机启动一些软件,下班时候,需要关掉一些软件.一个一个打开和关闭貌似是很繁琐的,于是乎,这个脚本产生了. 2. 环 ...

  8. [React Native] Installing and Linking Modules with Native Code in React Native

    Learn to install JavaScript modules that include native code. Some React Native modules include nati ...

  9. oracle2c-r2(12.2.0.1) 的镜像

    docker- 构建 oracle2c-r2(12.2.0.1) 的镜像   需求 由于公司的数据库需要使用新的oracle版本(12c-r2 -->12.2.0.1),从之前的oracle11 ...

  10. 01_Git的安装和简单使用(命令行模式+图形化模式)

      刚开始用git的小白适用,参考链接:http://www.cnblogs.com/qijunjun/p/7137207.html  实际项目开发中,我们经常会用一些版本控制器来托管自己的代码,今天 ...