我放弃。似乎无法使这个非常基本的事情起作用。请帮忙...
我正在尝试将图像从 URL 加载到可滚动的、捏合/缩放的屏幕上。
这是我的代码片段,它产生一个空白的白色屏幕。我选择将它放在 viewDidAppear 中:
@property (weak, nonatomic) UIScrollView *scrollView;
@property (weak, nonatomic) UIImageView *imageView;
...
- (void)viewDidAppear:(BOOL)animated {
NSData *photoData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlForImage]];
UIImage *photoImage = [[UIImage alloc] initWithData:photoData];
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
[self.scrollView setContentSize:photoImage.size];
[self.scrollView setMinimumZoomScale:1];
[self.scrollView setMaximumZoomScale:5];
[self.view addSubview:self.scrollView];
self.imageView = [[UIImageView alloc] initWithImage:photoImage];
[self.imageView setContentMode:UIViewContentModeScaleAspectFit];
[self.imageView setFrame:self.view.frame];
[self.scrollView addSubview:self.imageView];
}
我还实现了 viewForZoomingInScrollView:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
我得到一个白屏。我错过了什么?先感谢您。