我有一个简单的 if 语句来检测方向并执行操作。这很好用,但它只在第一次工作,并且无法再次检测到它。
这是否void
只被调用一次,如果是这样,我该如何改变它以不断检查?
我需要移动一些viewDidLoad
吗?
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self.navigationController pushViewController:graphView animated:YES];
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
[self.navigationController pushViewController:graphView animated:YES];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
[self.navigationController popToRootViewControllerAnimated:YES];
NSLog(@"portrait");
}
else
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}