<pre name="code" class="objc">//添加手势
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] init];
[recognizer addTarget:self action:@selector(tapPhoto:)];
[photoView addGestureRecognizer:recognizer];
* 监听图片的点击
*/
- (void)tapPhoto:(UITapGestureRecognizer *)recognizer
{
//1.添加一个遮盖
UIView *cover = [[UIView alloc] init];
cover.frame = [UIScreen mainScreen].bounds;
cover.backgroundColor = [UIColor blackColor];
[[UIApplication sharedApplication].keyWindow addSubview:cover];
//2.添加图片到遮盖上
StatusPhotoView *photoView = (StatusPhotoView *)recognizer.view;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = photoView.image;
//将photoView.frame从self坐标转为cover坐标系
imageView.frame = [cover convertRect:photoView.frame fromView:self];
[cover addSubview:imageView];
//3.放大
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = imageView.frame;
frame.size.width = cover.frame.size.width;
frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
frame.origin.x = 0;
frame.origin.y = (cover.frame.size.height - frame.size.height) * 0.5;
imageView.frame = frame;
}];
}