UIScrollView setZoomScale:动画混乱scrollView纵横比
我正在开发一个应用程序,其视图包含 UISCrollView,其中包含 UIImageView。
当视图即将出现时,我执行 setZoomScale 操作:
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"bounds of current view");
NSLog(@"widht: %f, height: %f", self.view.bounds.size.width,self.view.bounds.size.height);
NSLog(@"size of the image");
NSLog(@"widht: %f, height: %f", self.imageView.image.size.width,self.imageView.image.size.height);
NSLog(@"size of the scrollView BEFORE resizing");
NSLog(@"widht: %f, height: %f", self.scrollView.contentSize.width,self.scrollView.contentSize.height);
[self.scrollView setZoomScale:0.5 animated:NO];
NSLog(@"size of the scrollView AFTER resizing");
NSLog(@"widht: %f, height: %f", self.scrollView.contentSize.width,self.scrollView.contentSize.height);
}
问题是,如果图像是方形的,则应用 setZoomScale 后,scrollView 不再是方形的。以下是运行上述代码的输出:
2012-01-16 21:41:01.678 WorldTour[22781:f803] bounds of current view
2012-01-16 21:41:01.680 WorldTour[22781:f803] widht: 320.000000, height: 367.000000
2012-01-16 21:41:01.681 WorldTour[22781:f803] size of the image
2012-01-16 21:41:01.682 WorldTour[22781:f803] widht: 612.000000, height: 612.000000
2012-01-16 21:41:01.683 WorldTour[22781:f803] size of the scrollView BEFORE resizing
2012-01-16 21:41:01.683 WorldTour[22781:f803] widht: 612.000000, height: 612.000000
2012-01-16 21:41:01.684 WorldTour[22781:f803] size of the scrollView AFTER resizing
2012-01-16 21:41:01.685 WorldTour[22781:f803] widht: 306.000000, height: 259.500000
因此,运行代码后,612x612 的方形滚动视图变成了 306x259.5。 我缺少什么?出了什么问题?
不应该 [self.scrollView setZoomScale:0.5 动画:NO];以同样的方式变换高度和宽度?
I am developing an app with a view that holds a UISCrollView, inside which is a UIImageView.
When the view is about to appear, I perform a setZoomScale operation:
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"bounds of current view");
NSLog(@"widht: %f, height: %f", self.view.bounds.size.width,self.view.bounds.size.height);
NSLog(@"size of the image");
NSLog(@"widht: %f, height: %f", self.imageView.image.size.width,self.imageView.image.size.height);
NSLog(@"size of the scrollView BEFORE resizing");
NSLog(@"widht: %f, height: %f", self.scrollView.contentSize.width,self.scrollView.contentSize.height);
[self.scrollView setZoomScale:0.5 animated:NO];
NSLog(@"size of the scrollView AFTER resizing");
NSLog(@"widht: %f, height: %f", self.scrollView.contentSize.width,self.scrollView.contentSize.height);
}
The problem is that if the image is a square one, after applying setZoomScale the scrollView is not square anymore. Here is the output of running the above code:
2012-01-16 21:41:01.678 WorldTour[22781:f803] bounds of current view
2012-01-16 21:41:01.680 WorldTour[22781:f803] widht: 320.000000, height: 367.000000
2012-01-16 21:41:01.681 WorldTour[22781:f803] size of the image
2012-01-16 21:41:01.682 WorldTour[22781:f803] widht: 612.000000, height: 612.000000
2012-01-16 21:41:01.683 WorldTour[22781:f803] size of the scrollView BEFORE resizing
2012-01-16 21:41:01.683 WorldTour[22781:f803] widht: 612.000000, height: 612.000000
2012-01-16 21:41:01.684 WorldTour[22781:f803] size of the scrollView AFTER resizing
2012-01-16 21:41:01.685 WorldTour[22781:f803] widht: 306.000000, height: 259.500000
So, after running the code, a square scrollView of 612x612 turns out to be 306x259.5.
What am I missing? What is going wrong?
Shouldn't [self.scrollView setZoomScale:0.5 animated:NO]; transform height and width the same way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,经过多次尝试,我终于成功了!我不知道到底是什么导致了问题,但是在故事板中选择了滚动视图后,我选择了 XCode 中的属性检查器,然后取消选中“自动调整子视图大小”。取消勾选后一切正常。滚动视图已正确调整大小。
我解决了这个问题,但不明白是什么导致了这个问题,所以如果你知道为什么会发生这种情况,请随时发表评论!
Ok, after a lot of tries I finally got it working! I don't know exactly what was causing the problem, but with the scrollView selected in the storyboard I selected the Attributes Inspector inside XCode, and then unchecked "Autoresize Subviews". After unchecking it, it all works ok. The scrollView is correctly resized.
I solved this but don't understand what's causing the problem, so if you know why this happens feel free to comment!