iOS全屏展示图片(三种情况实现)
来源:互联网 发布:淘宝订餐 编辑:程序博客网 时间:2024/06/01 20:18
最近遇到一个需求:放大在页面中的图片,以达到展示的效果
这是一个全屏展示图片的小demo,主要分三种情况来实现:
1.正常页面中的ImageView
///主要使用了这两个方法+ (void)showImage:(UIImageView*)avatarImageView{UIImage *image =avatarImageView.image;// 获得根窗口UIWindow *window =[UIApplication sharedApplication].keyWindow;UIView *backgroundView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, ZOOMVCWIDTH, ZOOMVCHEIGHT)];oldframe =[avatarImageView convertRect:avatarImageView.bounds toView:window];backgroundView.backgroundColor =[UIColor blackColor];backgroundView.alpha =0.5;UIImageView *imageView =[[UIImageView alloc]initWithFrame:oldframe];imageView.image =image;imageView.tag =1;[backgroundView addSubview:imageView];[window addSubview:backgroundView];//点击图片缩小的手势UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];[backgroundView addGestureRecognizer:tap];[UIView animateWithDuration:0.3 animations:^{imageView.frame =CGRectMake(0,([UIScreen mainScreen].bounds.size.height-image.size.height*[UIScreen mainScreen].bounds.size.width/image.size.width)/2, [UIScreen mainScreen].bounds.size.width, image.size.height*[UIScreen mainScreen].bounds.size.width/image.size.width);backgroundView.alpha =1;}];}+ (void)hideImage:(UITapGestureRecognizer *)tap{UIView *backgroundView =tap.view;UIImageView *imageView =(UIImageView *)[tap.view viewWithTag:1];[UIView animateWithDuration:0.3 animations:^{imageView.frame =oldframe;backgroundView.alpha =0;} completion:^(BOOL finished) {[backgroundView removeFromSuperview];}];}
2.Tableview的cell上的图片
///tableview cell这个,主要使用了UIView的类方法, animateWithxxxUIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:9999];//小图的frameself.oldFrame = CGRectMake(cell.frame.origin.x+imageView.frame.origin.x, cell.frame.origin.y+imageView.frame.origin.y-self.tabView.contentOffset.y, imageView.frame.size.width, imageView.frame.size.height); //得到cell上的图片位置if (![self.bigImgView superview]) {self.bigImgView.image = imageView.image;[self.view.window addSubview:self.bigImgView];self.bigImgView.frame = self.oldFrame;[UIView animateWithDuration:0.5 animations:^{self.bigImgView.frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);} completion:^(BOOL finished) {[UIApplication sharedApplication].statusBarHidden=YES;}];}
3.CollectioinView的cell上的图片
collection使用了一个第三方,冯大师的PhotoBroswer/** 展示网络图片*/-(void)networkImageShow:(NSUInteger)index{__weak typeof(self) weakSelf=self;[PhotoBroswerVC show:self type:PhotoBroswerVCTypeModal index:index photoModelBlock:^NSArray *{NSArray *networkImages=@[@"http://www.netbian.com/d/file/20150519/f2897426d8747f2704f3d1e4c2e33fc2.jpg",@"http://www.netbian.com/d/file/20130502/701d50ab1c8ca5b5a7515b0098b7c3f3.jpg",@"http://www.netbian.com/d/file/20110418/48d30d13ae088fd80fde8b4f6f4e73f9.jpg",@"http://www.netbian.com/d/file/20150318/869f76bbd095942d8ca03ad4ad45fc80.jpg",@"http://www.netbian.com/d/file/20110424/b69ac12af595efc2473a93bc26c276b2.jpg",@"http://www.netbian.com/d/file/20130502/701d50ab1c8ca5b5a7515b0098b7c3f3.jpg",@"http://www.netbian.com/d/file/20110418/48d30d13ae088fd80fde8b4f6f4e73f9.jpg",@"http://www.netbian.com/d/file/20150318/869f76bbd095942d8ca03ad4ad45fc80.jpg",@"http://www.netbian.com/d/file/20110424/b69ac12af595efc2473a93bc26c276b2.jpg",@"http://www.netbian.com/d/file/20130502/701d50ab1c8ca5b5a7515b0098b7c3f3.jpg",@"http://www.netbian.com/d/file/20110418/48d30d13ae088fd80fde8b4f6f4e73f9.jpg",@"http://www.netbian.com/d/file/20150318/869f76bbd095942d8ca03ad4ad45fc80.jpg",@"http://www.netbian.com/d/file/20110424/b69ac12af595efc2473a93bc26c276b2.jpg",@"http://www.netbian.com/d/file/20140522/3e939daa0343d438195b710902590ea0.jpg",@"http://www.netbian.com/d/file/20141018/7ccbfeb9f47a729ffd6ac45115a647a3.jpg",];NSMutableArray *modelsM = [NSMutableArray arrayWithCapacity:networkImages.count];for (NSUInteger i = 0; i< networkImages.count; i++) {PhotoModel *pbModel=[[PhotoModel alloc] init];pbModel.mid = i + 1;// pbModel.title = [NSString stringWithFormat:@"这是标题%@",@(i+1)];// pbModel.desc = [NSString stringWithFormat:@"我是一段很长的描述文字我是一段很长的描述文字我是一段很长的描述文字我是一段很长的描述文字我是一段很长的描述文字我是一段很长的描述文字%@",@(i+1)];pbModel.image_HD_U = networkImages[i];//源frameUIImageView *imageV =(UIImageView *) weakSelf.collectionView.subviews[i];pbModel.sourceImageView = imageV;[modelsM addObject:pbModel];}return modelsM;}];}
具体代码详见github,如果帮到了您,麻烦给个star,O(∩_∩)O谢谢
1 0
- iOS全屏展示图片(三种情况实现)
- IOS 图片切换展示的实现
- iOS实现图片自动轮播展示
- iOS-使用imageView添加图片无法展示的三种解决方案
- iOS全屏查看图片
- jquery全屏图片幻灯片展示特效
- iOS开发笔记:实现点击图片放大全屏
- iOS开发笔记:实现点击图片放大全屏
- 图片全屏预览实现
- GsyVideoPlayer视频分析(三)------------全屏实现
- 原生js实现全屏展示效果
- iOS 图片模糊效果三种实现方式
- iOS循环饮用的三种情况
- iOS 列表上方 图片展示
- Xamarin.iOS 展示圆形图片
- jquery插件整理篇(三)图片展示插件
- 用全屏DialogFragment代替Activity,结合ViewPager展示图片
- 实现点击图片放大全屏
- 关系型数据库和非关系型数据库的区别2
- Qt下载地址
- js防止事件冒泡
- CentOS 安装 semanage 命令
- elasticsearch基本概念
- iOS全屏展示图片(三种情况实现)
- linux常用命令
- 恢复误删除的git stash记录 (how to retrieve a deleted git stash)
- 从入门到深入Fiddler (一)
- JPype:实现在python中调用JAVA
- Audio笔记之AudioMixer
- iOS命令行自动打包(archive)
- JVM初探- 内存分配、GC原理与垃圾收集器
- shell expect交互