1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #import "ViewController.h"
@interface ViewController () @property (weak, nonatomic) IBOutlet UIButton *iconButton; @property (nonatomic,strong) UIButton *cover; @end @implementation ViewController
- (UIButton *)cover { if (_cover==nil) {
_cover=[[UIButton alloc]initWithFrame:self.view.bounds]; _cover.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.5]; [self.view addSubview:_cover]; _cover.alpha=0.0; [_cover addTarget:self action:@selector(smallImage:) forControlEvents:UIControlEventTouchUpInside]; } return _cover; } //放大图片 - (IBAction)bigImage:(UIButton *)sender { //1.添加蒙版(遮罩) [self cover]; //2.将图像按钮放到最前面 [self.view bringSubviewToFront:self.iconButton]; //3.动画放大图像按钮 CGFloat w=self.view.bounds.size.width; CGFloat h=w; CGFloat y=(self.view.bounds.size.height-h)*0.5; [UIView animateWithDuration:1.0f animations:^{ self.iconButton.frame=CGRectMake(0,y, w, h); self.cover.alpha=1.0; }]; }
//缩小图片 -(void)smallImage:(UIButton *)cover { //将图像恢复初始位置 [UIView animateWithDuration:1.0 animations:^{ self.iconButton.frame=CGRectMake(112, 160, 150, 150); cover.alpha=0.0; } completion:^(BOOL finished) { //删除cover //[cover removeFromSuperview]; }]; }
@end
|