天天看点

按钮图片的放大缩小 用按钮控制 也可点击按钮图片

- (IBAction)big {

//    1.添加阴影

//      1.1创建阴影

    UIButton *cover = [[UIButton alloc]initWithFrame:self.view.bounds];

//      1.2添加

    [self.view addSubview:cover];

//      1.3设置颜色

    cover.backgroundColor = [UIColor blackColor];

//      1.4设置透明度

    cover.alpha = 0.0;

    self.cover = cover;

//      1.5阴影添加点击事件

    [cover addTarget:self action:@selector(smallImage) forControlEvents:UIControlEventTouchUpInside];

//    2.调整阴影和头像的位置

    [self.view bringSubviewToFront:self.head];

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0];

    cover.alpha = 0.6;

//    3.修改头像的frame

    CGFloat headX = 0;

    CGFloat headW = self.view.frame.size.width;

    CGFloat headH = headW;

    CGFloat headY = (self.view.frame.size.height - headH)*0.5;

    self.head.frame = CGRectMake(headX, headY, headW, headH);

    [UIView commitAnimations];

}

- (void)smallImage{

    [UIView animateWithDuration:1.0 animations:^{

        // 1.图片缩小

        self.head.frame = CGRectMake(123, 177, 120, 120);

        self.cover.alpha = 0.0;

    } completion:^(BOOL finished) {//动画完成后让阴影消失

        // 2.阴影消失

        [self.cover removeFromSuperview];

    }];

}

- (IBAction)headClick {

    if (self.cover == nil) {// 表示没有阴影,变大

        [self big];

    }else{//有阴影,变小

        [self smallImage];

    }

}