UIScrollView setZoomScale:动画混乱scrollView纵横比
我正在开发一个带有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的方形scrollView变为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?
好的,经过多次尝试后我终于开始工作了!我不确切知道导致问题的原因,但是在故事板中选择了scrollView,我在XCode中选择了Attributes Inspector,然后取消选中Autoresize Subviews。取消选中后,一切正常。 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!