我基本上是在运行这段代码:
UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(statusBarOrientation == UIInterfaceOrientationPortrait){
NSLog(@"orientation is portrait");
}
但是,无论模拟器或我的 iPad 中的实际方向如何,它都在打印“方向是纵向”。无论方向如何,尝试将 statusBarOrientation NSLog 为 %d 也会返回 1。
我坚持这是我的应用程序委托(delegate)、我的 View Controller 和我需要它的类,它们是同一件事。我的 info.plist/target 设置支持所有 4 种设备方向。
有没有人有确定界面方向的可靠方法,或者为什么我的不工作?谢谢
最佳答案
如果您不喜欢使用通知进行定向。然后也使用以下方法。
这是 iPad 中仅横向方向和 iPhone 中纵向的示例...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(interfaceOrientation==UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
return YES;
else
return NO;
}
else
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
关于iphone - iPad 方向未正确返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8875162/