代码如下
#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;
}];
}
使用简便,导入即用。
网友评论