self.view.bounds无法在纵向视图中工作

时间:2012-02-25 07:26:22

标签: objective-c xcode uiscrollview

我有一个全屏滚动视图。我正在加载两张图片。在横向模式下工作正常,但在纵向模式下,图像比屏幕大,所以我只能看到它们的一部分。看来self.view.bounds没有提供正确的屏幕尺寸

 CGRect frameForView1 = self.view.bounds;
 CGRect frameForView2 = self.view.bounds;

 image1 = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:fullpath]];
 [image1 setFrame:frameForView1];
 [self.scrollView addSubview:image1];
 [image1 release];

 frameForView2.origin.x = frameForView2.size.width;
 image2 = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:fullpath]];
 [image2 setFrame:frameForView2];
 [self.scrollView addSubview:image2];
 [image2 release];

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 2, self.scrollView.frame.size.height);

1 个答案:

答案 0 :(得分:1)

作为快速修复,您应该检查屏幕的方向,并为给定方向硬连接已知视图值。

BOOL isLandscape = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation);
if(isLandscape)
    //do something with landscape frame values
else(doSomethingElse)
    //do something with portrait frame values