UIScrollView setZoomScale:动画混乱scrollView纵横比

时间:2012-01-16 20:45:53

标签: objective-c ios5 uiscrollview uiimageview zoom

我正在开发一个app,其视图包含一个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的方形scrollView变为306x259.5。 我错过了什么?出了什么问题?

不应该[self.scrollView setZoomScale:0.5 animated:NO];转换高度和宽度的方式相同吗?

1 个答案:

答案 0 :(得分:3)

好的,经过多次尝试后我终于开始工作了!我不确切知道导致问题的原因,但是在故事板中选择了scrollView,我在XCode中选择了Attributes Inspector,然后取消选中“Autoresize Subviews”。取消选中后,一切正常。 scrollView已正确调整大小。

我解决了这个问题,但不明白导致问题的原因,所以如果您知道为什么会发生这种情况,请随时发表评论!

相关问题