美文网首页
ios 点击 imageView 查看大图

ios 点击 imageView 查看大图

作者: Sunny_Fight | 来源:发表于2016-09-05 19:04 被阅读3788次
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];
     }
     
     //点击图片后的方法(即图片的放大全屏效果)
- (void) cleckImageViewAction{
    NSLog(@"点击了图片");
    //创建一个黑色背景
    //初始化一个用来当做背景的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];
    
    //创建显示图像的视图
    //初始化要显示的图片内容的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;
    //添加点击手势(即点击图片后退出全屏)
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
    [browseImgView addGestureRecognizer:tapGesture];
    
    [self shakeToShow:bgView];//放大过程中的动画
}
-(void)closeView{

    [background removeFromSuperview];
}
//放大过程中出现的缓慢动画
- (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];
}

相关文章

网友评论

      本文标题:ios 点击 imageView 查看大图

      本文链接:https://www.haomeiwen.com/subject/mbgrettx.html