美文网首页
3DTouch Peek和Pop功能

3DTouch Peek和Pop功能

作者: 月咏蝴蝶 | 来源:发表于2016-01-04 14:30 被阅读1863次

在我们的app中使用3D Touch功能,主要分为以下三个模块:

  1. Home Screen Quick Actions
    点击主屏幕app图标呼出功能键,这部分功能在前一篇3D Touch简单使用已经讲了。

  2. peek and pop
    这个功能是点击某一个Cell,此时Cell会显示高亮状态(下面有图显示),其余部分模糊处理(以上这个操作称为Peek操作),在Peek操作下你还能进行两个深度操作:继续用手指按一下(这个操作就是Pop操作),或者向上拖动弹出来的这个视图。

  3. Force Properties
    这部分主要讲力度值,在这里我用不到也不会。

接受协议
@interface HomePageViewController ()<UIViewControllerPreviewingDelegate>

@end
注册方法
- (void)viewDidLoad {
    [super viewDidLoad];
    // 判断当前设备是否支持3DTouch
    if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
        [self registerForPreviewingWithDelegate:self sourceView:self.view];
    }
}
Peek 操作:(用力点击某一个Cell的效果)
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
    UIViewController *childVC = [[UIViewController alloc] init];
    CGRect rect = CGRectMake(20, 20, SCREEN_WIDTH - 40, SCREEN_HEIGHT - 40 - 64*2);
    previewingContext.sourceRect = rect;
    
    // 获取当前indexPath
    self.touchIndexPath = [self.apartTV indexPathForRowAtPoint:location];
    switch (self.touchIndexPath.row) {
        case 0:{
            ChartLineViewController *chartVC = [[ChartLineViewController alloc] init];
            chartVC.isCity = YES;
            chartVC.title = [self.viewModel.dataSource objectForKey:@"TITLE"];
            chartVC.city_name = [self.viewModel.dataSource objectForKey:@"TITLE"];
            childVC = (ChartLineViewController *)chartVC;
            break;
        }
        case 1:{
            DeviceViewController *deviceVC = [[DeviceViewController alloc] init];
            childVC = (DeviceViewController *)deviceVC;
            break;
        }
        case 2:{
            ChartLineViewController *chartVC = [[ChartLineViewController alloc] init];
            chartVC.title = [[[self.viewModel.dataSource objectForKey:@"SENSOR"] objectAtIndex:0] objectForKey:@"ps"];
            chartVC.isFirstSensor = true;
            chartVC.linesArray = [NSMutableArray arrayWithArray:[self deleteInvalidData]];
            childVC = (ChartLineViewController *)chartVC;
            break;
        }
        default:
            break;
    }
    return childVC;
}

Pop 操作:(用力继续某一个Cell之后弹出视图,再次Touch的效果)
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{
        self.navigationItem.backBarButtonItem = BACK_BARITEM;
    if (self.touchIndexPath.row == 0) {
        ChartLineViewController *chartVC = [[ChartLineViewController alloc] init];
        chartVC.isCity = YES;
        chartVC.title = [self.viewModel.dataSource objectForKey:@"TITLE"];
        chartVC.city_name = [self.viewModel.dataSource objectForKey:@"TITLE"];
        chartVC.refreshCityBlock = ^(NSString *title){
            self.isChangeCity = true;
            self.buttonTitle = title;
        };
        [self.navigationController pushViewController:chartVC animated:YES];
    }
    else if (self.touchIndexPath.row == 1){
        DeviceViewController *deviceVC = [[DeviceViewController alloc] init];
        [self.navigationController pushViewController:deviceVC animated:YES];
    }
    else{
        ChartLineViewController *chartVC = [[ChartLineViewController alloc] init];
        chartVC.title = [[[self.viewModel.dataSource objectForKey:@"SENSOR"] objectAtIndex:0] objectForKey:@"ps"];
        chartVC.isFirstSensor = true;
        chartVC.linesArray = [NSMutableArray arrayWithArray:[self deleteInvalidData]];
        [self.navigationController pushViewController:chartVC animated:YES];
    }
}

向上拖动弹出视图的操作
#pragma mark - 3DTouch Sliding Action
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems{
    UIPreviewAction *itemAdd = [UIPreviewAction actionWithTitle:@"添加" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        // 添加操作
    }];
    UIPreviewAction *itemDelete = [UIPreviewAction actionWithTitle:@"删除" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        // 删除操作
    }];
    return @[itemAdd,itemDelete];
}

sourceRect是peek触发时的高亮区域。这个区域内的View会高亮显示,其余的会模糊掉。
Peek操作效果图如下:

6E240204DF994C438D048CE7D9A2718B.png

Pop操作则是直接push到弹出视图,效果图就不上了。

向上拖动Peek操作效果图如下:

060AA8152A785E33A42BCB29590419FB.png

相关文章

  • 3DTouch Peek和Pop功能

    在我们的app中使用3D Touch功能,主要分为以下三个模块: Home Screen Quick Action...

  • iOS 3DTouch

    3DTouch是苹果在2015年,iPhone 6s、iOS9之后新推出的新功能。有Peek和Pop两种新手势。有...

  • iOS 3DTouch

    一.什么是3DTouch? 效果图: 点击icon: Peek(预览)和Pop(跳至预览的详细界面): 看完这个,...

  • 3DTouch_Peek and Pop

    Peek 和 Pop,全新功能登场。 Peek 和 Pop 让你能够预览所有类型的内容,甚至可对内容进行操作,却不...

  • 3DTouch(二) Peek和Pop功能实现

    代码下载链接:GitHub - jiangbin1993/3DTouch 欢迎下载点赞 上一篇文章介绍了3DTou...

  • 3DTouch中Peek与Pop

    效果如下:

  • 数据结构---数组栈

    interface push、pop、peek 实践---> ()[]{}、([)]

  • 栈、队列

    Stack先进后出,常用函数3P: peek push pop Queue先进先出,常用函数POP: peek o...

  • 如何在 Table view 中添加 3D Touch Peek

    Peek & Pop 在 iPhone 中是很实用的一个硬件相关特色功能,既可以提高操作效率,又有清晰的视觉表达。...

  • 关于3DTouch中Peek与Pop的正确使用

    前段时间花了点时间去研究了3DTouch这一块,咱们就来聊一下,看看怎么在app中集成3DTouch中peek p...

网友评论

      本文标题:3DTouch Peek和Pop功能

      本文链接:https://www.haomeiwen.com/subject/hthahttx.html