iOS 3D Touch 实现UITableViewCell 预览
来源:互联网 发布:重庆移动网络加速器 编辑:程序博客网 时间:2024/06/04 23:18
效果图好丑.
测试手机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;}
2 0
- iOS 3D Touch 实现UITableViewCell 预览
- ios 3D Touch功能的实现
- iOS之实现3D Touch
- ios 3D Touch功能的实现
- ios 3D Touch
- iOS 3D touch
- iOS 3D Touch
- iOS 3D Touch
- 利用 3D touch 的“Peek and Pop”实现视频预览
- iOS 9 新特性之实现 3D Touch
- IOS 实现3D Touch在tableView的简单应用
- iOS新特性之实现3D Touch
- 应用中实现 3D Touch ios swift
- iOS 3D Touch开发
- iOS 3D Touch功能
- iOS 3D touch 开发
- iOS 3D Touch功能
- iOS 3D Touch 简述
- 修改mysql root 密码
- c++文件操作和new相关
- ERROR: No viable tables matched specification
- 树莓派3-如何打开蓝牙
- centos6.5 ifconfig不显示eth0地址
- iOS 3D Touch 实现UITableViewCell 预览
- 微信第三方开发之全网发布
- elasticsearch 使用事项
- Spring-data-redis配置及使用示例
- CustomProgressDialog
- php几种运行模式总结
- C++作业6
- OGG-00850解决
- POJ3280-Cheapest Palindrome