旋转景观时,我正在显示模式视图控制器。我要画像时删除模态视图控制器。由于某种原因,进入纵向模式后,我的日志语句不会出现。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"showing chart");
[self presentModalViewController:landscapeChartViewController animated:NO];
}
if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"dismissing chart");
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
}
最佳答案
您可以稍微简化一下此代码,可能有助于缩小范围。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES; // Return YES is the same as entering all interfaces.
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
NSLog(@"showing chart");
[self presentModalViewController:landscapeChartViewController animated:NO];
}
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
NSLog(@"dismissing chart");
[self.parentViewController dismissModalViewControllerAnimated:NO];
// self.parentViewController seems like a call FROM the modalViewController.
// This should be moved to the modalViewControllers implementation
}
}
仅仅从它的角度来看,我认为您需要在模式视图内部而不是在父视图内部关闭模式视图控制器。因此,您将在主控制器中使用横向版本,然后将“ willAnimateRotation ...”添加到模态控制器以处理纵向旋转状态。
关于iphone - 无法在iPhone上检测人像方向,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6554886/