3D Touch是一种立体触控技术,被苹果称为新一代多点触控技术,是在Apple Watch上采用的Force Touch,屏幕可感应不同的感压力度触控。3D Touch,苹果iPhone 6s的新功能,看起来类似 PC 上的右键。有Peek Pop 两种新手势。
2015年9月10日,苹果在新品发布会上宣布了3D-Touch功能。
2016年6月13日,苹果开发者大会WWDC在旧金山召开,会议宣布可以在待机画面用3D Touch操作通知。
产品介绍
用力按一个图标会弹出一层半透明菜单,里面包含了该应用下的一些快捷操作,在邮件列表上用力按也可以快速弹开窗口查看邮件,在邮件列表当中,用力按邮件列表里的一条邮件就会显示完整邮件内容,松手就会关掉,无需左右滑动的打开关闭操作。轻点电话就可以查看最近联系人,按压相机可以快速自拍,按压图片库可以快速浏览大图
轻按弹出窗口预览邮件内容,增加拇指压力时则可以全屏,在日程安排中轻轻用力按航班信息即可弹出窗口显示航班信息。按住地图图标即可弹出一些快速选项,Instagram中可以直接进入自己的时间流或者友邻动态,在相机中可以通过轻按相机预览拍的照片,而且在iOS9中可以快速通过边缘轻按调出后台。可以说,3D-Touch大幅度提升了手机操作的效率。
新iPhone增加了3D-Touch技术,相对于多点触摸在平面二维空间的操作,3D-Touch技术增加了对力度和手指面积的感知,可以通过长按快速预览/查看你想要的短信/图片/超链接等内容,Peek和Pop手势的响应时间可迅捷到10ms和15ms。
相机与3D-Touch技术结合,相应的相机中增加拍摄动态图片的功能选项,查看时只需要用一定力道向图片按下去,图片就会动起来。
可以在待机画面用3D Touch操作通知。
ShortcutItem
初始化ShortcutItem
- (void)createItemsWithIcons {
// icons with my own images,icon size 35*35
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeFavorite];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeSearch];
UIApplicationShortcutIcon *icon3 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];
// create several (dynamic) shortcut items
UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.touch.deep1" localizedTitle:@"喜爱" localizedSubtitle:@"我的收藏" icon:icon1 userInfo:nil];
UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.touch.deep2" localizedTitle:@"搜索" localizedSubtitle:@"搜索活动" icon:icon2 userInfo:nil];
UIMutableApplicationShortcutItem *item3 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.touch.deep3" localizedTitle:@"分享" localizedSubtitle:@"分享到朋友圈" icon:icon3 userInfo:nil];
// add all items to an array
/**
* 防止不支持设备引起崩溃
*/
if (item1 && item2 && item3) {
NSArray *items = @[item1, item2, item3];
// add the array to our app
[UIApplication sharedApplication].shortcutItems = items;
}
}
ShortcutItem事件
- (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);
// have we launched Deep Link Level 1
if ([shortcutItem.type isEqualToString:@"com.touch.deep1"]) {
NSLog(@"clicked deep1");
PreviewViewController *vc = [PreviewViewController new];
self.window.rootViewController = vc;
[self.window makeKeyWindow];
}
if ([shortcutItem.type isEqualToString:@"com.touch.deep2"]) {
NSLog(@"clicked deep2");
[[LKGlobalNavigationController sharedInstance] pushViewControllerWithUrLPattern:PREVIEW_VIEW_CONTROLLER];
}
if ([shortcutItem.type isEqualToString:@"com.touch.deep3"]) {
NSLog(@"clicked deep3");
}
}
UIPreviewActionItem 快速操作
UIPreviewActionItem事件
// setup a list of preview actions
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"保存" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"Default Action triggered");
}];
UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"分享" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"Default Action triggered");
}];
UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"删除" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"Destructive Action triggered");
}];
// add them to an arrary
NSArray *actions = @[action1, action2, action3];
// add all actions to a group
// UIPreviewActionGroup *group1 = [UIPreviewActionGroup actionGroupWithTitle:@"Action Group" style:UIPreviewActionStyleDefault actions:actions];
// NSArray *group = @[group1];
// and return them (return the array of actions instead to see all items ungrouped)
return actions;
}
Peek And Pop 预览
注册UIViewControllerPreviewingDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestTableViewCell"];
// Enable to use "-sizeThatFits:"
cell.fd_enforceFrameLayout = NO;
cell.entity = self.titleArray[indexPath.row%10];
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:self sourceView:cell];
}
return cell;
}
实现UIViewControllerPreviewingDelegate
# pragma mark - 3D Touch Delegate
// 轻压显示预览页面
// check if we're not already displaying a preview controller
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
if ([self.presentedViewController isKindOfClass:[DetailViewController class]]) {
return nil;
}
DetailViewController *detailView = [[DetailViewController alloc] init];
return detailView;
}
// 重压显示详情页面
// alternatively, use the view controller that's being provided here (viewControllerToCommit)
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self showViewController:viewControllerToCommit sender:self];
}