美文网首页
iOS之放大头像

iOS之放大头像

作者: 明似水 | 来源:发表于2017-02-18 11:58 被阅读37次
    放大头像

    查看大图的方法

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

    大图变回小图

    -(void) clickView {
        
        [UIView animateWithDuration:1.0 animations:^{
            // 1. 通过动画的方式,设置遮罩透明度为 0,
            self.bigView.alpha = 0;
        } completion:^(BOOL finished) {
            // 2. 动画执行完毕之后要执行的代码
            // 动画执行完毕之后,将遮罩从父控件中移除,并清空
            [self.bigView removeFromSuperview];
            self.bigView = nil;
        }];
        
    }
    

    END.

    相关文章

      网友评论

          本文标题:iOS之放大头像

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