问题描述
我正在开发一个应用程序,其视图包含一个 UISCrollView,内部是一个 UIImageView.
I am developing an app with a view that holds a UISCrollView, inside which is a UIImageView.
当视图即将出现时,我执行了 setZoomScale 操作:
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);
}
问题是如果图像是正方形的,在应用 setZoomScale 之后,scrollView 就不再是正方形了.这是运行上述代码的输出:
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
因此,运行代码后,612x612 的方形滚动视图变成了 306x259.5.我错过了什么?出了什么问题?
So, after running the code, a square scrollView of 612x612 turns out to be 306x259.5. What am I missing? What is going wrong?
不应该 [self.scrollView setZoomScale:0.5 animated:NO];用同样的方式变换高度和宽度?
Shouldn't [self.scrollView setZoomScale:0.5 animated:NO]; transform height and width the same way?
推荐答案
好的,经过多次尝试,我终于成功了!我不知道到底是什么导致了这个问题,但是在故事板中选择了滚动视图,我选择了 XCode 中的属性检查器,然后取消选中自动调整子视图".取消选中后,一切正常.scrollView 已正确调整大小.
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!
这篇关于UIScrollView setZoomScale:animated messes scrollView 纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!