UIScrollView + UIImage and zoom: not fluid

2019-06-09 00:33发布

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.

2条回答
Deceive 欺骗
3楼-- · 2019-06-09 01:16

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

查看更多
登录 后发表回答