点击放大图片

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *minImageView;
@property(nonatomic,strong)UIView *background;

@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _minImageView.userInteractionEnabled = YES;
    //添加点击手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    [_minImageView addGestureRecognizer:tapGesture];
}
//点击图片方法
- (void) tapAction{

    UIView *bgView = [[UIView alloc]initWithFrame:self.view.bounds];
    _background = bgView;
    [self.view addSubview:bgView];
    
    //创建显示图像的视图
    //初始化要显示的图片内容的imageView(这里位置继续偷懒...没有计算)
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    //要显示的图片,即要放大的图片
    [imgView setImage:[UIImage imageNamed:@"timg1.jpg"]];
    [bgView addSubview:imgView];
    
    imgView.userInteractionEnabled = YES;
    //添加点击手势(即点击图片后退出全屏)
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
    [imgView addGestureRecognizer:tapGesture];
    

}
-(void)closeView{
    [_background removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

推荐阅读更多精彩内容