ios 點擊 imageView 查看大圖

Untitled.gif
  • 直接擼代碼:
#import <QuartzCore/QuartzCore.h>
@property (nonatomic, assign) UIView *background;//圖片放大

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //允許 imageView 用戶交互
    //允許用戶交互
    _personalView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cleckImageViewAction)];
    [_personalView addGestureRecognizer:tapGesture];
     }
     
     //點擊圖片后的方法(即圖片的放大全屏效果)
- (void) cleckImageViewAction{
    NSLog(@"點擊了圖片");
    //創建一個黑色背景
    //初始化一個用來當做背景的View。
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MyKScreenWidth, MyKScreenHeight)];
    background = bgView;
    [bgView setBackgroundColor:[UIColor colorWithRed:0/250.0 green:0/250.0 blue:0/250.0 alpha:1.0]];
    //[self.view addSubview:bgView];
    [[ZWYHelper rootTabbarViewController].view addSubview:bgView];
    
    //創建顯示圖像的視圖
    //初始化要顯示的圖片內容的imageView
    UIImageView *browseImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MyKScreenWidth, MyKScreenHeight - 64)];
    browseImgView.contentMode = UIViewContentModeScaleAspectFit;
    self.browseImgView = browseImgView;
    //要顯示的圖片,即要放大的圖片
    _browseImgView.image = _headImgIDView.image;
    [bgView addSubview:browseImgView];
    
    browseImgView.userInteractionEnabled = YES;
    //添加點擊手勢(即點擊圖片后退出全屏)
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
    [browseImgView addGestureRecognizer:tapGesture];
    
    [self shakeToShow:bgView];//放大過程中的動畫
}
-(void)closeView{

    [background removeFromSuperview];
}
//放大過程中出現的緩慢動畫
- (void) shakeToShow:(UIView*)aView{
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = 0.3;
    NSMutableArray *values = [NSMutableArray array];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    animation.values = values;
    [aView.layer addAnimation:animation forKey:nil];
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容