iOS查看大图

代码如下

#pragma mark 查看大图的方法

-(void) datu :(UIImage *) img {

CGFloat iconW = self.view.frame.size.width;

CGFloat iconH = iconW;

CGFloat iconX = 0;

CGFloat iconY = (self.view.frame.size.height - iconH) * 0.5;

UIView *bigView = [[UIView alloc] init];

bigView.frame = self.view.bounds;

bigView.backgroundColor = [UIColor blackColor];

bigView.alpha = 0;

self.bigView = bigView;

UITapGestureRecognizer *viewTap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickView)];

[bigView addGestureRecognizer:viewTap];

[self.view addSubview:bigView];

UIImageView *imgView = [[UIImageView alloc] init];

imgView.frame = CGRectMake(iconX, iconY, iconW, iconH);

imgView.image = img;

[bigView addSubview:imgView];

[UIView animateWithDuration:0.5 animations:^{

bigView.alpha = 1;

}];

}

#pragma mark 大图变回小图

-(void) clickView {

[UIView animateWithDuration:1.0 animations:^{

// 1. 通过动画的方式,设置遮罩透明度为 0,

self.bigView.alpha = 0;

} completion:^(BOOL finished) {

// 2. 动画执行完毕之后要执行的代码

// 动画执行完毕之后,将遮罩从父控件中移除,并清空

[self.bigView removeFromSuperview];

self.bigView = nil;

}];

}

使用简便,导入即用。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容