放大頭像
查看大圖的方法
-(void) datu :(UIImage *) img {
CGFloat iconW = self.view.frame.size.width;
CGFloat iconH = iconW;
CGFloat iconX = 0;
CGFloat iconY = (self.view.frame.size.height - iconH) * 0.5;
UIView *bigView = [[UIView alloc] init];
bigView.frame = self.view.bounds;
bigView.backgroundColor = [UIColor blackColor];
bigView.alpha = 0;
self.bigView = bigView;
UITapGestureRecognizer *viewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickView)];
[bigView addGestureRecognizer:viewTap];
[self.view addSubview:bigView];
UIImageView *imgView = [[UIImageView alloc] init];
imgView.frame = CGRectMake(iconX, iconY, iconW, iconH);
imgView.image = img;
[bigView addSubview:imgView];
[UIView animateWithDuration:0.5 animations:^{
bigView.alpha = 1;
}];
}
大圖變回小圖
-(void) clickView {
[UIView animateWithDuration:1.0 animations:^{
// 1. 通過動畫的方式,設置遮罩透明度為 0,
self.bigView.alpha = 0;
} completion:^(BOOL finished) {
// 2. 動畫執行完畢之后要執行的代碼
// 動畫執行完畢之后,將遮罩從父控件中移除,并清空
[self.bigView removeFromSuperview];
self.bigView = nil;
}];
}
END.