美文网首页
iOS查看大图

iOS查看大图

作者: LLVKS | 来源:发表于2017-04-06 17:40 被阅读199次

    代码如下

    #pragma mark 查看大图的方法

    -(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;

    }];

    }

    #pragma mark 大图变回小图

    -(void) clickView {

    [UIView animateWithDuration:1.0 animations:^{

    // 1. 通过动画的方式,设置遮罩透明度为 0,

    self.bigView.alpha = 0;

    } completion:^(BOOL finished) {

    // 2. 动画执行完毕之后要执行的代码

    // 动画执行完毕之后,将遮罩从父控件中移除,并清空

    [self.bigView removeFromSuperview];

    self.bigView = nil;

    }];

    }

    使用简便,导入即用。

    相关文章

      网友评论

          本文标题:iOS查看大图

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