【发布时间】:2012-07-30 03:26:05
【问题描述】:
我在旋转设备时尝试更改视图布局时遇到了一些麻烦,我有一个名为 OverviewViewController 的主视图,它包含 2 个视图,当设备处于某个方向时,它们将被隐藏/显示。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// do some layout stuff
NSLog(@"OverviewViewController shouldAutorotateToInterfaceOrientation");
return YES;
}
每次我旋转我的设备时,这个方法都会执行两次,但是在任何子视图中它都不会被调用;
// In OverviewViewController
_landscapeView = [[LandscapeOverviewViewController alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:_landscapeView.view];
// In LandscapeOverviewViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
NSLog(@"LandscapeOverviewViewController: shouldAutorateToInterfaceOrientation");
// Only change orientation when it's landscape
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES;
return NO;
}
子视图不响应设备方向是否有原因?该方法从未在那里被调用过。
【问题讨论】:
-
你是说,在旋转时,overviewViewController 调用 shouldAutorotateToInterfaceOrientation 方法,但 LandscapeOverviewViewController 不调用 shouldAutorotateToInterfaceOrientation ?
-
@calvinBhai 这正是我的意思,是的。
-
@Luke,谢谢你,但它没有解释如何解决它。
-
该方法执行了两次,因为在 iOS5 上,旋转和呈现之间存在一些内部不一致。即它在旋转和演示之前被调用。在 iOS6 上,这已被更改。
标签: iphone orientation device