ios 3D Touch
2015-11-09 17:53
435 查看
3D Touch的触控技术,被苹果称为新一代多点触控技术。其实,就是此前在Apple
Watch上采用的Force Touch,屏幕可感应不同的感压力度触控
3D Touch,苹果iPhone 6s的新功能,看起来类似 PC 上的右键。有Peek Pop 两种新手势,2015年9月10日,苹果在新品发布会上宣布了3D-Touch功能。
Peek和Pop
现在你可以授权应用的视图控制器来响应用户不同的按压力量。随着用户按压力量的增加,交互会出现三个阶段:
1. 暗示内容预览是可使用的
2. 展示预览(peek),和快捷选项菜单(peek quick actions)
3. 可选的跳转到预览中的视图(pop)
当你使用 peek 和 pop 时,系统通过压力决定从哪个阶段过度至下一个。用户可以在设置>通用>辅助功能>3D Touch中进行修改。
暗示peek是可使用的
轻按后,周围内容会变得模糊,这告诉用户预览更多内容( peek )是可以使用的。
Peek
轻按,屏幕视图就会过渡到 peek,一个你设置的用来展示更多内容的视图-就像Mail app做的一样。如果用户这时结束了触碰,peek就会消失并且应用回到交互开始之前的状态。
或者这个时候,用户可以在peek界面上更用力按下来跳转到使用peek呈现的视图,这个过渡动画会使用系统提供的pop过渡。pop出来的视图会填满你应用的根视图并显示一个返航按钮可以回到交互开始的地方。(图中没有显示最后展示pop视图的阶段)
代码段如下(最低在 xcode7.0版本以上):
在 AppDelegate.m 中
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
//判断先前我们设置的唯一标示符
if ([shortcutItem.type isEqualToString:@"-11.UITouchText.share"]) {
NSArray *arr = @[@"hello 3D Touch"];
UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:nil];
[self.window.rootViewController presentViewController:vc animated:YES completion:^{
}];
}
if ([shortcutItem.type isEqualToString:@"-11.UITouchText.Search"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
SearchViewController *search = [storyboard instantiateViewControllerWithIdentifier:@"searchID"];
UINavigationController *nac = [[UINavigationController alloc] initWithRootViewController:search];
[self.window.rootViewController presentViewController:nac animated:YES completion:^{
}];
}
if ([shortcutItem.type isEqualToString:@"-11.UITouchText.play"]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
picker.allowsEditing = YES;//设置可编辑
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self.window.rootViewController presentViewController:picker animated:YES completion:nil];//进入图片库
}
}
//在Viewcontroller写一个长按手势用于区分长按和3dtouch 的区别
_longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction)];
#pragma mark 检验3Dtouch
- (void)check3Dtouch{
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:self sourceView:self.view];
NSLog(@"3D touch 开启状态");
_longPress.enabled = NO;
return;
}
_longPress.enabled = YES;
}
#pragma mark 预览代理方法
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
_temp = (location.y / 100) - 1;
PreviewController *previewC = [[PreviewController alloc] init];
previewC.view.frame = self.view.frame;
UIImageView *er = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_array[_temp]]];
previewC.view = er;
return previewC;
}
#pragma mark 上拉代理方法
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems{
UIPreviewAction *p1 =[UIPreviewAction actionWithTitle:@"分享" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享了" message:@"你好" delegate: self cancelButtonTitle:@"嗯嗯" otherButtonTitles:@"说的对啊", nil];
[alert show];
}];
UIPreviewAction *p2 =[UIPreviewAction actionWithTitle:@"收藏" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏了" message:@"你好" delegate: self cancelButtonTitle:@"艾玛" otherButtonTitles:@"呵呵", nil];
[alert show];
}];
NSArray *actions = @[p1,p2];
return actions;
}
Watch上采用的Force Touch,屏幕可感应不同的感压力度触控
3D Touch,苹果iPhone 6s的新功能,看起来类似 PC 上的右键。有Peek Pop 两种新手势,2015年9月10日,苹果在新品发布会上宣布了3D-Touch功能。
Peek和Pop
现在你可以授权应用的视图控制器来响应用户不同的按压力量。随着用户按压力量的增加,交互会出现三个阶段:
1. 暗示内容预览是可使用的
2. 展示预览(peek),和快捷选项菜单(peek quick actions)
3. 可选的跳转到预览中的视图(pop)
当你使用 peek 和 pop 时,系统通过压力决定从哪个阶段过度至下一个。用户可以在设置>通用>辅助功能>3D Touch中进行修改。
暗示peek是可使用的
轻按后,周围内容会变得模糊,这告诉用户预览更多内容( peek )是可以使用的。
Peek
轻按,屏幕视图就会过渡到 peek,一个你设置的用来展示更多内容的视图-就像Mail app做的一样。如果用户这时结束了触碰,peek就会消失并且应用回到交互开始之前的状态。
或者这个时候,用户可以在peek界面上更用力按下来跳转到使用peek呈现的视图,这个过渡动画会使用系统提供的pop过渡。pop出来的视图会填满你应用的根视图并显示一个返航按钮可以回到交互开始的地方。(图中没有显示最后展示pop视图的阶段)
代码段如下(最低在 xcode7.0版本以上):
在 AppDelegate.m 中
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
//判断先前我们设置的唯一标示符
if ([shortcutItem.type isEqualToString:@"-11.UITouchText.share"]) {
NSArray *arr = @[@"hello 3D Touch"];
UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:nil];
[self.window.rootViewController presentViewController:vc animated:YES completion:^{
}];
}
if ([shortcutItem.type isEqualToString:@"-11.UITouchText.Search"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
SearchViewController *search = [storyboard instantiateViewControllerWithIdentifier:@"searchID"];
UINavigationController *nac = [[UINavigationController alloc] initWithRootViewController:search];
[self.window.rootViewController presentViewController:nac animated:YES completion:^{
}];
}
if ([shortcutItem.type isEqualToString:@"-11.UITouchText.play"]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
picker.allowsEditing = YES;//设置可编辑
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self.window.rootViewController presentViewController:picker animated:YES completion:nil];//进入图片库
}
}
//在Viewcontroller写一个长按手势用于区分长按和3dtouch 的区别
_longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction)];
#pragma mark 检验3Dtouch
- (void)check3Dtouch{
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:self sourceView:self.view];
NSLog(@"3D touch 开启状态");
_longPress.enabled = NO;
return;
}
_longPress.enabled = YES;
}
#pragma mark 预览代理方法
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
_temp = (location.y / 100) - 1;
PreviewController *previewC = [[PreviewController alloc] init];
previewC.view.frame = self.view.frame;
UIImageView *er = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_array[_temp]]];
previewC.view = er;
return previewC;
}
#pragma mark 上拉代理方法
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems{
UIPreviewAction *p1 =[UIPreviewAction actionWithTitle:@"分享" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享了" message:@"你好" delegate: self cancelButtonTitle:@"嗯嗯" otherButtonTitles:@"说的对啊", nil];
[alert show];
}];
UIPreviewAction *p2 =[UIPreviewAction actionWithTitle:@"收藏" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏了" message:@"你好" delegate: self cancelButtonTitle:@"艾玛" otherButtonTitles:@"呵呵", nil];
[alert show];
}];
NSArray *actions = @[p1,p2];
return actions;
}
相关文章推荐
- iOS小demo之image图形(简单的image)
- iOS 静态库和动态库的区别&静态库的生成
- [iOS] 地图坐标的坑
- iOS每日小结-01续
- iOS开发日记45-ARC和内存管理
- iOS开发企业版ipa分发 以及在线安装
- iOS获取当前版本号 Bundle Id等信息的方法
- IOS XCode6.4 安装报错
- iOS设计模式之工厂模式
- iOS 9 ContactsFramework
- iOS开发之textfield(自用帖)
- iOS 【NewGroupFromSelection-contentView-imageNamed:nil】
- 利用Core Plot绘制柱状图
- iOS 集成支付宝遇到的问题(续)
- 实现QQ的第三方登录 iOS开发
- iOS在线播放视频
- iOS 【boundingRectWithSize】
- 多个ScrollView的时候点击statusbar失效的解决方法(ios自学笔记)
- IOS学习——TableView详细解释
- iOS9 相册的进入及显示图片