0

I have view controller, and inside that I have a UIScrollView, for managing the zoom, and a UIImage. Now I'm handling the zoom effect with UIScrollViewDelegate delegate and method viewForZoomingInScrollView:... but the result is very poor, definitely not fluid!

This is my code:

#import "ImageViewController.h"

@interface ImageViewController () <UIScrollViewDelegate, UIActionSheetDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.scrollView.delegate = self;
    self.scrollView.maximumZoomScale = 3.0;

    // some code
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.imageView;
}
// last update
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    if ([self.scrollView zoomScale] < 1.0) {
        [self.scrollView setZoomScale:1.0];
    }
}

// some other methods...

@end

This is the storyboard view:

I'm not using a Pinch Gesture Recognizer. All images are quite small like 640x480.

Thanks

P.S. this is a continue of UICollectionView and images.

Community
  • 1
  • 1
jacoz
  • 3,508
  • 5
  • 26
  • 42
  • I can't see anything wrong here. When you say it's not fluid, do you mean it's jerky when zooming / panning / both? – mattjgalloway Oct 24 '12 at 17:16
  • Yes, a lot! I mean, when I zoom in Pictures or even in other App, like Twitter or IMDB, the zoom i very fluid! – jacoz Oct 24 '12 at 17:22
  • Well from the code and screenshot you posted, I can't see anything wrong. So the problem must lie elsewhere. Are you doing some intensive work in `scrollViewDidZoom:` maybe? – mattjgalloway Oct 24 '12 at 17:23
  • I posted a video to show you the problem: http://youtu.be/XbW-7umSbsQ ...maybe is everything alright and it's only about iOS Simulator! – jacoz Oct 25 '12 at 10:09
  • Can you show some more code of the `UIScrollViewDelegate` methods you implement please? – mattjgalloway Oct 25 '12 at 10:17
  • I've just edited my post adding `scrollViewDidZoom:` method. – jacoz Oct 25 '12 at 10:22
  • Is that the only one you implement? – mattjgalloway Oct 25 '12 at 10:54
  • Does this help you - http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content - it's a tutorial I wrote. The first part is exactly what you need to implement. – mattjgalloway Oct 25 '12 at 10:55
  • That tutorial looks awesome! that's exactly what I want. As soon as I have some time off, I'll take a look. Thanks a lot!! – jacoz Oct 25 '12 at 15:32
  • I've added an answer with that then. Hope it works for you! – mattjgalloway Oct 25 '12 at 15:37

2 Answers2

4

Checkout out this tutorial I wrote. The first part is exactly what you need to implement.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
  • @mattjgalloway Any chance the tutorial gets updated to work with iOS 6 autolayout feature?. Embedding a UIImageView inside a UIScrollView and get it to scroll and zoom is not that straightforward with autolayout.. – Diego Allen Jan 24 '13 at 18:47
  • @mattjgalloway: awesome tutorial about scroll + image . – Toseef Khilji Jan 20 '14 at 07:06
0

This has been addressed in other posts:

Zooming image views with autolayout:

Centering logic for autolayout or springs and struts

Community
  • 1
  • 1
Chris Conover
  • 8,889
  • 5
  • 52
  • 68