@interface HMViewController () @property (nonatomic, strong) UIButton *cover; //阴影 @end
@implementation HMViewController //懒加载,阴影
- (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(bigImage) forControlEvents:UIControlEventTouchUpInside];
}
return _cover;
} /** 调整状态栏颜色 */
/**
UIStatusBarStyleDefault 黑色状态栏
UIStatusBarStyleLightContent 亮色状态栏
*/
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
} /**
* 大图小图显示切换
*/
- (IBAction)bigImage
{
// 如果没有放大,就放大,否则就缩小
// 通过蒙板的alpha来判断按钮是否已经被放大
if (self.cover.alpha == 0.0) { // 放大
// 2. 将图像按钮弄到最前面
// bringSubviewToFront将子视图前置
[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(, y, w, h);
self.cover.alpha = 1.0;
}];
} else { // 缩小
[UIView animateWithDuration:1.0 animations:^{
// 将图像恢复初始位置
self.iconButton.frame = CGRectMake(, , , );
self.cover.alpha = 0.0;
}];
}
}
@end