// tableView中的图片,点击后可以放大置全屏, 再点击缩小会原来位置 // #import "HMViewController.h" @interface HMViewController ()<UITableViewDataSource, UITableViewDelegate> @property (nonatomic, assign) CGRect fristFrame; // 存储每次要展示的图片frame, 方便缩小时使用 @property (nonatomic, strong) UIImageView *fullImageView; // 全屏展示的视图 @property (nonatomic, weak) UITableView *tableView; // tableview @end @implementation HMViewController // 懒加载全屏视图 - (UIImageView *)fullImageView { if (_fullImageView == nil) { // 视图和屏幕一样大 _fullImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 设置为可交互, 不然, 后面的手势根本不能用 _fullImageView.userInteractionEnabled = YES; // 添加点击手势 ( 缩小图片时使用 ) [_fullImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap2:)]]; // 设置视图内容填充模式. _fullImageView.contentMode = UIViewContentModeScaleAspectFit; } return _fullImageView; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; UITableView *tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds]; tableView.delegate = self; tableView.dataSource = self; self.tableView = tableView; [self.view addSubview:tableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 20; } /* 该方法中的注释代码为自定义imageView */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // UIImageView *imageView;// 自定义ImageView, static NSString *ID = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; // imageView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 5, 30, 30)]; // imageView.userInteractionEnabled = YES; // imageView.tag = 1; // 自定义imageView时方便获取 // [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(actionTap:)]]; // [cell.contentView addSubview:imageView]; // cell的imageView设置为可交互 cell.imageView.userInteractionEnabled = YES; // 添加点击手势 ( 放大图片时使用 ) [cell.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(actionTap:)]]; } // 自定义imageView时使用 // imageView.image = [UIImage imageNamed:@"1"]; cell.imageView.image = [UIImage imageNamed:@"1"];// 设置图片 return cell; } /** * 图片放大 */ -(void)actionTap:(UITapGestureRecognizer *)sender{ // 根据点击手势的坐标,获取被点击的cell CGPoint loaction = [sender locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:loaction]; UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath]; // 自定义imageView时使用 // UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:1]; // 从cell中获取imageView UIImageView *imageView = cell.imageView; // 转换坐标系 // 转换cell中的imageView的frame 在self.view中的坐标系 CGRect newFrame = [imageView convertRect:imageView.bounds toView:self.view]; // 保存被点击的图片的frame, 缩小时使用 self.fristFrame = newFrame; // if (![self.fullImageView superview]) { // 貌似没用, 检查是否有父视图 // 设置全屏视图中的图片 self.fullImageView.image = imageView.image; // 设置frame起始位置(动画开始位置) self.fullImageView.frame = self.fristFrame; // 设置背景颜色 self.fullImageView.backgroundColor = [UIColor blackColor]; // 添加到视图上面 [self.view addSubview:self.fullImageView]; // 动画效果展示为全屏 [UIView animateWithDuration:0.5 animations:^{ self.fullImageView.frame = [UIScreen mainScreen].bounds; }]; // } } /** * 图片缩小 */ -(void)actionTap2:(UITapGestureRecognizer *)sender{ // 清除背景颜色 self.fullImageView.backgroundColor = [UIColor clearColor]; // 缩小图片动画 [UIView animateWithDuration:0.5 animations:^{ self.fullImageView.frame = self.fristFrame; // 动画缩小到初始位置 } completion:^(BOOL finished) { [self.fullImageView removeFromSuperview];// 从父视图中移除全屏视图 }]; } @end
相关推荐
qt Tableview显示数据
能动态显示和隐藏tableview前方图片,可以代替setEditing方法中的打钩!
tableView点击更多,展开显示,显示效果不错,有什么问题还望大家提出宝贵意见,谢谢了
Qt QListWidget 缩略图列表显示图片
ios tableview 异步 加载图片
包含MYSQL的数据库连接,TableView的表格设置,排序model的使用,数据库数据行数统计,每页只显示10行,每页中的每列可以排序,能删除选定行,增加一行,跳转到第一页、上一页、下一页、最后页,点击单元格可以修改...
tableVIew点击展开
实现TableView下拉图片放大效果,图片等比缩放,仅仅实现下拉放大,上拉图片保持原状
swift ,使用autolayout + storyboard 最外层tableview列表,cell里面嵌套了tableview,自适应内容,cell里的tableview不可滑动,内容全部显示,且文字分行显示,不用设置cell的高度直接可以自适应内容
iOS TableView 下拉图片放大 上拉图片高度缩小 TableViewFrame动态变化
iOS数据库SQLite3基本操作并将内容显示在tableView中
使用RunLoop优化tableView加载大量图片卡顿问题,可有效解决主线程阻塞问题
IPhone TableView 图片异步加载
ios中tableview下拉出发tableview更新的效果实现。 iPhone5.1 测试成功
tableView点击标题,显示更多,头部有搜索栏
IOS开发 tableview中cell的用法 值得拥有
这是Qt中tableWidget和tableView的简单使用。
1、UITableViewTest主要在本地数据库获取了全国所有的地区,省,市的数据用列表的方式显示出来。 2、UITableView的section头显示地区。 3、省列表可以展开显示城市列表。实现了UITableView的嵌套显示。 4、...
只用简单几句代码就可以构建出tableview下拉图片放大的效果
横屏的tableview使用方法