我在使用时UIScrollView没有设置它。contentOffsetzoomToRect
我有UIScrollView一个UIImageView里面。滚动和缩放本身到目前为止工作。现在我想在应用程序开始时为滚动视图提供图像视图的某个缩放矩形。为此,我实现zoomToRect:了它并且设置zoomsScale正确,但它没有设置contentOffset.
使用时的预期结果zoomToRect是UIScrollView根据所选矩形进行放大或缩小,并contentOffset根据给定zoomToRect方法的矩形的原点坐标进行设置。
实际行为是它缩放到正确位置zoomScale,但我UIImageView始终位于原点 0,0,而不是我在 中指定的矩形的 x (475) 和 y (520) 坐标的预期原点zoomToRect。
我的图像尺寸是 1473x1473。
这是一些代码
- (void)viewDidLoad {
CGRect bounds = self.view.frame;
_imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgImage.png"]];
self.containerView = [[UIView alloc] initWithFrame:bounds];
_containerView.contentMode = UIViewContentModeCenter;
_scrollView = [[UIScrollView alloc] initWithFrame:bounds];
_scrollView.delegate = self;
_scrollView.contentSize = _imageView.bounds.size;
_scrollView.minimumZoomScale = 0.2;
[_scrollView addSubview:_containerView];
[_containerView addSubview:_imageView];
[self.view addSubview:_scrollView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[_scrollView zoomToRect:CGRectMake(475.0, 150.0, 520.0, 747.0) animated:NO];
}
#pragma mark UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _containerView;
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
[self printVisibleRectToConsole:scrollView];
CGSize newImageViewSizeWithScale = CGSizeMake(_imageView.bounds.size.width * _scrollView.zoomScale,
_imageView.bounds.size.height * _scrollView.zoomScale);
_scrollView.contentSize = newImageViewSizeWithScale;
}
我的问题:
- 为什么不
zoomToRect设置contentOffset? - 我怎样才能按预期
zoomToRect改变我的?contentOffset