zoukankan      html  css  js  c++  java
  • 单击双击放大图片

    -(void)create{   

     _scrollerView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, YHScreemW, YHScreemH)];

        

        _scrollerView.showsVerticalScrollIndicator = NO;

        _scrollerView.showsHorizontalScrollIndicator = NO;

        _scrollerView.minimumZoomScale = 1.0;

        _scrollerView.maximumZoomScale = 2.0;

        _scrollerView.delegate = self;

        [self.view addSubview:_scrollerView];

        

        

        //粘贴一张图片

        _imageView = [[UIImageView alloc] init];

        _imageView.frame = CGRectMake(0, 0, _scrollerView.frame.size.width, _scrollerView.frame.size.height);

        _imageView.center = CGPointMake(_scrollerView.frame.size.width/2, _scrollerView.frame.size.height/2);

        _imageView.contentMode = UIViewContentModeScaleAspectFit;

        [_imageView setImage:[UIImage imageWithData:_picData]];

        [_imageView setUserInteractionEnabled:YES];

        [_scrollerView addSubview:_imageView];

        

        

        

        //添加双击事件

        UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];

        [doubleTapGesture setNumberOfTapsRequired:2];

        [_imageView addGestureRecognizer:doubleTapGesture];

        

        

        //添加双击事件

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

        [singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];//没有这个单击会阻挡双击

        [_imageView addGestureRecognizer:singleTapGesture];

    }

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

    {

        return _imageView;

    }

    - (void)handleDoubleTap:(UIGestureRecognizer *)gesture

    {

        CGFloat zoomScale = _scrollerView.zoomScale;

        zoomScale = (zoomScale == 1.0) ? 2.0 : 1.0;

        CGRect zoomRect = [self zoomRectForScale:zoomScale withCenter:[gesture locationInView:gesture.view]];

        [_scrollerView zoomToRect:zoomRect animated:YES];

    }

    - (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center

    {

        CGRect zoomRect;

        zoomRect.size.height =_scrollerView.frame.size.height / scale;

        zoomRect.size.width  =_scrollerView.frame.size.width  / scale;

        zoomRect.origin.x = center.x - (zoomRect.size.width  /2.0);

        zoomRect.origin.y = center.y - (zoomRect.size.height /2.0);

        return zoomRect;

    }

    -(void)singleTapGesture{

        

        [self dismissViewControllerAnimated:YES completion:nil];

        

    }

  • 相关阅读:
    ASCII码对照表
    createPopup 超链接
    说说回车键触发表单提交的问题
    linux下配java环境的小结
    spring bind checkbox 传递值问题
    用Common validator为springMVC做验证时遇到的一个问题小记
    [转载]对android LinearLayout中layout_weight属性使用初探
    linux下tomcat启动正常,但用http://22.22.33.33:8080却访问不了,防火墙的设置问题
    Java 遍历Map时 删除元素
    ftp用户登录时不能进自己的目录,被拒绝登录的解决方法
  • 原文地址:https://www.cnblogs.com/yeng/p/5865493.html
Copyright © 2011-2022 走看看