单双击手势

 //添加手势

BOOL            _large;

//双击手势

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

        doubleTap.numberOfTapsRequired = 2;

        [imgView addGestureRecognizer:doubleTap];

  //单机手势    

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

        singleTap.numberOfTapsRequired = 1;

        [imgView addGestureRecognizer:singleTap];

        [singleTap requireGestureRecognizerToFail:doubleTap];

 

//单机手势

- (void)singleTap:(UITapGestureRecognizer *)gesture

{

    UIImageView *imgView = (UIImageView *)gesture.view;

    UIWindow *window = [[UIApplication sharedApplication] keyWindow];

    self.view.backgroundColor = [UIColor clearColor];

    scroll.backgroundColor = [UIColor clearColor];

    [window addSubview:imgView];

    [imgView removeFromSuperview];

    [self dismissViewControllerAnimated:NO completion:nil];

}

 

- (void)doubleTap:(UITapGestureRecognizer *)gesture

{

    UIScrollView *scl = (UIScrollView *)gesture.view.superview;

    

    if (scl.zoomScale == scl.maximumZoomScale) {

        

        [scl setZoomScale:1.0 animated:YES];

        _large = NO;

        _zoomingScrollView = nil;

        return;

    }

    

    if (_large) {

        

        [scl setZoomScale:1.0 animated:YES];

        _large = NO;

        _zoomingScrollView = nil;

        

    }else{

        

        CGPoint location = [gesture locationInView:gesture.view];

        [scl zoomToRect:CGRectMake(location.x, location.y, 1, 1) animated:YES];

        _large = YES;

        _zoomingScrollView = scl;

    }

}

 

posted @ 2016-10-24 15:02  柳仙慧子  阅读(138)  评论(0编辑  收藏  举报