UIScrollView + UIImage and zoom: not fluid

与世无争的帅哥 提交于 2019-12-10 12:19:32

问题


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.


回答1:


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




回答2:


This has been addressed in other posts:

Zooming image views with autolayout:

Centering logic for autolayout or springs and struts



来源:https://stackoverflow.com/questions/13053486/uiscrollview-uiimage-and-zoom-not-fluid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!