iOS全屏展示图片(三种情况实现)

原文地址::https://blog.csdn.net/wwwwwwwwwwwwdi/article/details/53994415

 

相关文章

1、如何启动app时全屏显示Default.png(图片)?----https://www.cnblogs.com/zhanglei8831/p/5842633.html

2、iOS 如何设置一整张图片作为背景图片(穿透导航栏)----https://blog.csdn.net/qq_30513483/article/details/51098495

 

这是一个全屏展示图片的小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的类方法, animateWithxxx
UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:9999];

//小图的frame
self.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];

//源frame
UIImageView *imageV =(UIImageView *) weakSelf.collectionView.subviews[i];
pbModel.sourceImageView = imageV;

[modelsM addObject:pbModel];
}

return modelsM;
}];
}

具体代码详见github,如果帮到了您,麻烦给个star,O(∩_∩)O谢谢
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值