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è)用來當(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)擊手勢(即點(diǎn)擊圖片后退出全屏)
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
[browseImgView addGestureRecognizer:tapGesture];
[self shakeToShow:bgView];//放大過程中的動(dòng)畫
}
-(void)closeView{
[background removeFromSuperview];
}
//放大過程中出現(xiàn)的緩慢動(dòng)畫
- (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];
}