zoukankan      html  css  js  c++  java
  • UIImageView 点击放大缩小

    static CGRect oldframe;

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

        }];

    }

  • 相关阅读:
    自学android半年,已从.net转型成android程序员,分享下这个过程(转)
    深入浅出jsonp
    对程序员说点实在话(转)
    浅谈iOS学习之路(转)
    Quartz Cron表达式 在线生成器
    AutoMapper使用笔记
    毕业两年工作三年小结
    C#转C++的一点分享
    手机数据抓包以及wireshark技巧
    这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧。。。(转)
  • 原文地址:https://www.cnblogs.com/rollrock/p/5416428.html
Copyright © 2011-2022 走看看