点击放大图片

#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

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

推荐阅读更多精彩内容