Pinch To Zoom Effect on UIImageView inside scrollView?

后端 未结 6 1023
粉色の甜心
粉色の甜心 2020-12-05 15:05

I\'m using storyboard (iOS 6.0) to create a photo gallery viewer for my app. This is how my imageViewController is set up in storyboard:

相关标签:
6条回答
  • 2020-12-05 15:42

    You need to do what Wadi suggested above but also set the setMinimumZoomScale to be different from setMaximumZoomScale. They are both 1.0f by default.

    After that, the UIImageView should be pinchable

    0 讨论(0)
  • 2020-12-05 15:47

    Here is how Apple recomends to do what you want to do. I used the code provided by Apple and it worked like a charm! If you want to optimize memory management, you can use iCarousel (made by nicklockwood), which have a cache management for dealloc unused views!

    0 讨论(0)
  • 2020-12-05 15:52

    I have created a fully working demo application (similar in nature to Facebook's default photo gallery) which demonstrates pinch to zoom of Image View nested inside a scroll view with AutoLayout and storyboards. View my project here: http://rexstjohn.com/facebook-like-ios-photo-modal-gallery-swipe-gestures/.

    It also includes async photo loading via MKNetworkKit and gesture based swiping through a photo gallery. Enjoy and I hope it saves everyone time trying to figure this out because it is somewhat annoying.

    0 讨论(0)
  • 2020-12-05 15:56

    I think better solution in Apple Documentation

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    
    {
    
        return self.imageView;
    
    }
    - (void)viewDidLoad {
    
        [super viewDidLoad];
    
        self.scrollView.minimumZoomScale=0.5;
    
        self.scrollView.maximumZoomScale=6.0;
    
        self.scrollView.contentSize=CGSizeMake(1280, 960);
    
        self.scrollView.delegate=self;
    
    }
    

    Check Apple Documentation

    0 讨论(0)
  • 2020-12-05 15:56

    I've created a class to handle zooming of UIImageViews similar to Instagram. Might be what you're looking for, otherwise you can look at how I achieved it. https://github.com/twomedia/TMImageZoom

    0 讨论(0)
  • 2020-12-05 15:58

    The first step is to make sure your views have the correct delegates implemented. For example in the .m file

    @interface myRootViewController () <.., UIGestureRecognizerDelegate, UIScrollViewDelegate, ...>
    

    From the documentation, make sure you have this implemented:

    The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum ( minimumZoomScale) zoom scale must be different.

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    {
      return self.fullScreenView;
    }
    
    
    -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
    {}
    

    The scrollViewDidEndZooming method can stay empty for now. If you already did that or it still doesnt work, please post more of your code and then it is easier to help more specifically.

    0 讨论(0)
提交回复
热议问题