ios 點(diǎn)擊 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];
     }
     
     //點(diǎn)擊圖片后的方法(即圖片的放大全屏效果)
- (void) cleckImageViewAction{
    NSLog(@"點(diǎn)擊了圖片");
    //創(chuàng)建一個(gè)黑色背景
    //初始化一個(gè)用來(lái)當(dāng)做背景的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];
    
    //創(chuàng)建顯示圖像的視圖
    //初始化要顯示的圖片內(nèi)容的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;
    //添加點(diǎn)擊手勢(shì)(即點(diǎn)擊圖片后退出全屏)
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
    [browseImgView addGestureRecognizer:tapGesture];
    
    [self shakeToShow:bgView];//放大過(guò)程中的動(dòng)畫(huà)
}
-(void)closeView{

    [background removeFromSuperview];
}
//放大過(guò)程中出現(xiàn)的緩慢動(dòng)畫(huà)
- (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];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容