How to Zoom In/Out Photo on double Tap in the iPhone WWDC 2010 - 104 PhotoScroller

前端 未结 14 1758
野性不改
野性不改 2020-12-12 13:28

I am going through the Sample code of iPhone WWDC 2010 - 104 PhotoScroller App. It\'s working great with my project related images (PDF Page Images)

but I am struggl

14条回答
  •  情深已故
    2020-12-12 14:02

    This appears to work using convertRect:fromView: and zoomToRect:animated::

    -(void)tap:(UITapGestureRecognizer *)tapGestureRecognizer
    {
        CGFloat zoomeScaleMultiplier = 0.5;
        UIScrollView *scrollView = (UIScrollView *) tapGestureRecognizer.view;
        UIView *zoomableView = [scrollView.delegate viewForZoomingInScrollView:scrollView];
    
        CGRect rect = scrollView.bounds;
        rect.origin = CGPointZero;
    
        CGAffineTransform transform = CGAffineTransformMakeScale(zoomeScaleMultiplier, zoomeScaleMultiplier);
        rect = CGRectApplyAffineTransform(rect, transform);
    
        rect.origin = [tapGestureRecognizer locationInView:scrollView];
    
        rect = CGRectOffset(rect, CGRectGetWidth(rect)/-2., CGRectGetHeight(rect)/-2.);
    
        rect = [zoomableView convertRect:rect fromView:scrollView];
    
        [scrollView zoomToRect:rect animated:YES];
    }
    

提交回复
热议问题