您的位置:首页 > 产品设计 > UI/UE

3D-Touch Home Screen Quick Actions 使用

2015-11-04 19:01 507 查看
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(点击下载).

安装和使用也比较简单

安装 

git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.git cd SBShortcutMenuSimulator
make


安装完,在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


使用

// 'com.x.x' 为程序的bundle id, id可以随便指定
echo 'com.xxx.xxx' | nc 127.0.0.1 8000


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:@"3" localizedTitle:@"标题" localizedSubtitle:@"副标题" icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"本地图片"] userInfo:userInfo];

// 打开最后阅读的一本书
UIApplicationShortcutIcon *openBook = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeBookmark];
UIMutableApplicationShortcutItem *itemOpenBook = [[UIMutableApplicationShortcutItem alloc] initWithType:@"2" localizedTitle:@"打开最后阅读的书籍"];
itemOpenBook.icon = openBook;

// 找书
UIApplicationShortcutIcon *searchBook = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeSearch];
UIMutableApplicationShortcutItem *itemSearchBook = [[UIMutableApplicationShortcutItem alloc] initWithType:@"1" 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:@"1"]) {
NSLog(@"搜索书架");
} else if ([shortcutItem.type isEqualToString:@"3"]) {
NSDictionary *dict = shortcutItem.userInfo;
NSLog(@"dict为传递过来的参数");
}
}


3. 备注

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

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

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

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


  如果你不是在wb145230博客园看到本文,请点击查看原文.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: