iOS 全屏看大图

iOS 全屏看大图

-(void)showImage:(UIImageView *)avatarImageView{
    
    UIImage *image=avatarImageView.image;
    
    UIWindow *window=[UIApplication sharedApplication].keyWindow;
    
    UIView *backgroundView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    //小图frame
    oldframe =[avatarImageView convertRect:avatarImageView.bounds toView:window];
    
    backgroundView.backgroundColor=[UIColor blackColor];
    
    backgroundView.alpha=0;
    
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:oldframe];
    
    imageView.image=image;
    
    imageView.tag=1;
    
    [backgroundView addSubview:imageView];
    
    [window addSubview:backgroundView];
    
    
    
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
    
    [backgroundView addGestureRecognizer: tap];
    
    
    
    [UIView animateWithDuration:0.3 animations:^{
        
        imageView.frame=CGRectMake(0,([UIScreen mainScreen].bounds.size.height-image.size.height*[UIScreen mainScreen].bounds.size.width/image.size.width)/2, [UIScreen mainScreen].bounds.size.width, image.size.height*[UIScreen mainScreen].bounds.size.width/image.size.width);
        
        backgroundView.alpha=1;
        
    } completion:^(BOOL finished) {
        
        
        
    }];
    
}

-(void)hideImage:(UITapGestureRecognizer*)tap{
    
    UIView *backgroundView=tap.view;
    
    UIImageView *imageView=(UIImageView*)[tap.view viewWithTag:1];
    
    [UIView animateWithDuration:0.3 animations:^{
        
        imageView.frame=oldframe;
        
        backgroundView.alpha=0;
        
    } completion:^(BOOL finished) {
        
        [backgroundView removeFromSuperview];
        
    }];
    
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 自己做了几个项目,在接触到项目需要打包的时候是自己独立做的第二个项目,最开始项目打包都是同事完成的。iOS开...
    WenBo丨星空灬阅读 12,700评论 0 6
  • 今天是机械培训第六天,上午老师讲解了出工程图,尺寸标注,标题栏,明细表等内容。建立工程图可以打开一个模型,拉入所...
    鑫儿luna阅读 169评论 0 0
  • 《卖轮子》| 路七解读 关于作者 本书由杰夫 · 科克斯与霍华德 · 史蒂文斯联合写作,其中杰夫 · 科克斯是畅销...
    鸭梨山大哎阅读 312评论 0 1
  • iOS app -> 应用宝 操作流程: 1,应用宝 上传Android apk,审核通过; 2,点击微下载,添加...
    infoyou阅读 529评论 0 2
  • 过路人 曲:あなたがいた森 词: 泓溪 文案 一告别就淡了,风一吹就远了 我们都是过路人,谈不上谁对谁错 识得你在...
    泓溪ifeng阅读 688评论 0 0