【发布时间】:2011-07-28 10:47:06
【问题描述】:
网上的大部分示例代码都假设你的 UIScrollView 是全屏的。
我正在尝试创建一个内部只有一个 UIImageView 的 UIScrollView,并且只是希望能够像通常发生的那样进行缩放。我的 UIScrollView 只填充了屏幕的一部分,所以我不能像示例应用程序那样只使用自动调整大小来保持正确的大小。
我最接近的是将其添加到 UIScrollViewDelegate:
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
CGPoint cOffset = imageScrollView.contentOffset;
float cScale = imageScrollView.contentScaleFactor;
CGRect imageFrame = ptImage.frame;
float scale = scrollView.zoomScale;
imageFrame.size.width *= scale;
imageFrame.size.height *= scale;
ptImage.frame = imageFrame;
scrollView.zoomScale = 1.0;
scrollView.frame = CGRectMake(0.0, 0.0, scrollContainerView.frame.size.width, scrollContainerView.frame.size.height);
scrollView.bounds = CGRectMake(cOffset.x * cScale * scale , cOffset.y * cScale * scale, scrollView.bounds.size.width, scrollView.bounds.size.height);
scrollView.contentSize = imageFrame.size;
}
这里唯一的问题是边界偏移(scrollView.bounds = ...)不正确。
肯定比我在这里做的简单多了?
有什么帮助吗?
【问题讨论】:
标签: objective-c ios ipad uiscrollview