我在旋转设备时尝试更改视图布局时遇到了一些麻烦,我有一个名为 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;
}
子视图是否有理由不响应设备方向?该方法从未在那里被调用。