iOS 3D Touch 实现UITableViewCell 预览
2016-05-22 00:47
525 查看
效果图好丑.
测试手机iPhone6s , 也就是使用了新特性 3DTouch. 囧 不知道的以为会有多难.
在开始之前
UIViewControllerPreviewingDelegate // 签订这个协议
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; // 对每个cell指定代理, 大致是这个意思 [self registerForPreviewingWithDelegate:self sourceView:cell]; // cell.textLabel.text = self.arrayData[indexPath.row]; return cell; }
#pragma mark - peek的代理方法,轻按即可触发弹出vc - (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{ //通过[previewingContext sourceView]拿到对应的cell的数据; NSIndexPath *indexPath = [_tableView indexPathForCell:(UITableViewCell* )[previewingContext sourceView]]; // 用于显示预览的vc ListViewController *listVc = [[ListViewController alloc] init]; // 演示的是传入一个字符串 , 实际可能是你需要的model listVc.strText = [self.arrayData objectAtIndex:indexPath.row]; return listVc; } #pragma mark - pop的代理方法,在此处可对将要进入的vc进行处理 - (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit { }
在 ListViewController 中我用一个label作为演示的, 您可能还需要添加底部菜单(类似于 收藏 喜欢这样)
-(NSArray<id<UIPreviewActionItem>> *)previewActionItems { UIPreviewAction * action1 = [UIPreviewAction actionWithTitle:@"收藏" style:1 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"收藏"); }]; UIPreviewAction * action2 = [UIPreviewAction actionWithTitle:@"喜欢" style:0 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"喜欢"); }]; NSArray *items = @[action1,action2]; return items; }
相关文章推荐
- Ubuntu使用sudo命令出现must be setuid root错误的解决方法
- 60. Permutation Sequence
- LeetCode 63. Unique Paths II(唯一路径)
- LeetCode 62. Unique Paths
- UISplitViewController 分屏控制器
- UITableView初识(1)
- UITableView--多组数据显示
- 从技术实现角度看Android UI设计
- Arduino 和 MQ-135 空气污染气体传感器 实验
- iOS学习之UIView
- 29.UITabBarController
- Hive ORC和Parquet
- 【Leetcode】Longest Increasing Subsequence
- iOS中常用UI层方法总结
- iOS开发 ☞ UITextField 详解
- HDOJ/HDU 1297 Children’s Queue(推导~大数)
- HDOJ/HDU 1297 Children’s Queue(推导~大数)
- iOS开发中 UITableViewCell的几种样式
- Java中String、StringBuffer和StringBuilder的区别
- STL 简单 queue 的实现