ios 3D Touch

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;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值