[分享]iOS开发-图片点击点击放大

news/2024/7/3 21:56:16 标签: 移动开发

图片点击放大,再次点击返回原视图.完美封装,一个类一句代码即可调用.IOS完美实现

创建了一个专门用于放大图片的类,以下为.h文件

#import

<foundation foundation.h="">

 

@interface

SJAvatarBrowser : NSObject

 //@brief  浏览头像

 //@param  oldImageView    头像所在的imageView


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

 

@end</foundation>

以下为.m文件

#import

"SJAvatarBrowser.h"

static

CGRect oldframe;

@implementation

SJAvatarBrowser

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

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

   }];
}

@end 


引入此类之后,为自己需要放大的imageView添加tap手势

UITapGestureRecognizer
 *tap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(magnifyImage)];

 

[self.imageView addGestureRecognizer:tap];






-(void)magnifyImage

{

    NSLog(@"局部放大");

    [SJAvatarBrowser
 showImage:self.imageView];//调用方法

}


分享来源:
http://blog.csdn.net/ssrrxx11...


http://www.niftyadmin.cn/n/1152222.html

相关文章

优化mysql

数据库设计和表创建时就要考虑性能sql的编写需要注意优化分区分表分库1.数据库设计和表创建时就要考虑性能 mysql数据库本身高度灵活&#xff0c;造成性能不足&#xff0c;严重依赖开发人员能力。也就是说开发人员能力高&#xff0c;则mysql性能高。这也是很多关系型数据库的通…

阿里OSS FormApi Content-Disposition不生效的问题

Oss FormApi官方参考&#xff1a;PostObject 请求语法&#xff1a; 请求参数&#xff08;部分&#xff09;&#xff1a; 注意&#xff1a; ‘file’这个表单域需要放置在“最后一个域”中&#xff0c;否则处于file之后的表单域不保证一定能生效&#xff0c;例如之前把Content-…

记一次意想不到的Istio调用配置

想要使用Istio的前提&#xff0c;就是在服务的namespace上开启sidecar自动注入 kubectl label namespace xxx istio-injectionenabled --overwrite 之后我们再在K8s集群中部署服务时&#xff0c;就会发现Deployment下的pod内会多了一个sidecar&#xff08;istio-proxy&#xff…

做市场的人,不一定知道什么才是“市场”

2019独角兽企业重金招聘Python工程师标准>>> 做营销&#xff0c;首先要懂市场。 编者按&#xff1a;本文转载至微信公众号“李叫兽”&#xff08;ID&#xff1a;Professor-Li&#xff09;&#xff0c;作者李靖。转载已获授权&#xff0c;版权归原作者所有&#xff0…

美团CAT集成

CAT客户端集成&#xff08;原官方集成方式&#xff09; 官方Github参考&#xff1a;cat-master-java-README.zh-CN.md 1.在应用所在容器&#xff08;主机 或 docker容器&#xff09;中创建/data/appdatas/cat, /data/applogs/cat&#xff08;记录日志&#xff0c;可选&#x…

外网映射工具

frp 服务端配置 [common] bind_addr 0.0.0.0 bind_port 8990 vhost_http_port 8980dashboard_addr 0.0.0.0 dashboard_port 7501dashboard_user ev dashboard_pwd Extremevision2018!log_file ./frps.log log_level infolog_max_days 3 客户端配置 [common] server_…

Linux 容器技术史话:从 chroot 到未来

Linux 容器是一个在单一 Linux 主机上提供多个隔离的 Linux 环境的操作系统级虚拟技术。不像虚拟机&#xff08;VM&#xff09;&#xff0c;容器并不需要运行专用的访客&#xff08;guest&#xff09;操作系统。容器们共享宿主机的&#xff08;host&#xff09;操作系统内核&am…

Feign在K8s中的使用

之前在SpringCloud中使用过FeignClient的方式对服务进行调用&#xff0c;感觉使用起来还是很方便的&#xff0c;所以想要探索一下是否可以把FeignClient用在K8s集群中进行服务间的调用&#xff1b; feign是一个声明式web服务调用的客户端&#xff0c;创建一个接口并加上注解就…