search

Home  >  Q&A  >  body text

ios - 请教:scrollView中无法用viewForZoomingInScrollView方法缩放

按照教程,在scrollView中使用viewForZoomingInScrollView方法进行图片缩放,编译成功,但是无法缩放。

代码如下:

#import "ViewController.h"

@interface ViewController () <UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"minion"]];
    
    [self.scrollView addSubview:imageView];
    self.scrollView.contentSize = imageView.image.size;
    
    self.scrollView.delegate = self;
    self.scrollView.maximumZoomScale = 3.0;
    self.scrollView.minimumZoomScale = 0.2;

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return self.imageView;
}
PHP中文网PHP中文网2889 days ago415

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:58:03

    The property UIImageView has no value assigned

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:58:03

    Can UIImageView be displayed? What about changing it to strong?

    In addition, the contentSize of scrollView is set to the size of the image. How big is the size of the image?

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:58:03

    ScrollView is not initialized...

    reply
    0
  • Cancelreply