打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ios中点击图片放大,再次点击缩小的类的封装





.h文件:-----------------------------------------

#import <Foundation/Foundation.h>


@interface ZoomImage : NSObject

/**

 * @brief 点击图片放大,再次点击缩小

 *

 * @param oldImageView 头像所在的imageView

 */

+(void)showImage:(UIImageView*)avatarImageView;

@end

.m文件:-----------------------------------------

#import "ZoomImage.h"

static CGRect oldframe;

@implementation ZoomImage


+(void)showImage:(UIImageView*)avatarImageView

{

    UIImage *image =avatarImageView.image;

    UIWindow *window =[UIApplication sharedApplication].keyWindow;

    UIView *backgroundView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

    oldframe =[avatarImageView convertRect:avatarImageView.bounds toView:window];

    backgroundView.backgroundColor =[UIColor blackColor];

    backgroundView.alpha =0.5;

    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;

    }];

}

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

    }];



}

@end

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
UIScrollView 和UIPageControl 实现app启动滑动图
iphone开发我的新浪微博客户端-用户登录自定义弹出窗口篇(1.2)
iOS——UIView背景图片设置
IOS UI 第四篇:基本UI
iOS程序-UIScrollView实现图片缩放
更改UIView的背景
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服