我编写了一个具有 UIViewController 的应用程序,它在纵向模式下显示另一个 UIViewController,在横向模式下显示另一个 UIViewController。
当我去风景时,我会画/放置东西,所以我需要得到风景坐标。下面是当 iPhone 旋转时触发新视图的代码。下面的代码是这个视图的加载方式。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)x
duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(x))
{
NSLog(@"Going Portrait");
} else if (UIInterfaceOrientationIsLandscape(x))
{
NSLog(@"Going Landscape");
if (activeView != [graphViewController view])
{
[containerView addSubview:[graphViewController view]];
}
}
}
我的问题是,当
-(void)loadView {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
NSLog(@"GraphViewController: Screenbounds %@", NSStringFromCGRect(screenBounds));
}
在 GraphViewController 返回时,它会产生: GraphViewController: Screenbounds {{0, 0}, {320, 480}}
这不是风景坐标,因此我的画是不正确的。如何使 GraphViewController 在调用[UIScreen mainScreen] bounds] 时具有正确的坐标;?
非常感谢
麦克风