【发布时间】:2011-10-19 01:02:16
【问题描述】:
我有一个非常奇怪的问题,我至今无法诊断。
在我的 iOS 应用程序(它是一个通用二进制文件)中,当我在 iPad 4.3 上运行时,启动时的方向不一致。
应用委托将启动画面 (UIViewController) 添加到主窗口,然后将其移除并添加应用的主视图。问题在于这个主视图 - 大约一半的时间,它以横向正确加载,另一半以纵向加载视图(尽管状态栏和键盘都正确地以横向加载)。
当我不对代码或模拟器/设备方向进行任何更改时,为什么启动时的方向会发生变化,我有点茫然。
我在 Info.plist 中将 UIInterfaceOrientationLandscapeLeft 和 UIInterfaceOrientationLandscapeRight 设置为 iPad 唯一支持的方向,并且每个视图控制器都使用以下内容:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iPhone 3.2 or later.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
} else {
// The device is an iPhone or iPod touch.
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
}
return NO;
}
谁能帮我解决这个问题?
干杯,
奥利
【问题讨论】:
-
好的,我解决了这个问题。原来 iPad 不喜欢我添加和删除视图的方式。我将启动视图添加为窗口的 rootViewController,然后将其删除并将我的主视图添加为 rootViewController。我通过添加一个导航控制器(navigationBarHidden = YES)作为窗口的 rootViewController,然后将我的初始屏幕添加为导航控制器的根来解决了这个问题。然后我只需将主视图推送到堆栈上。仍然不确定为什么 iPad 不喜欢我原来的方法,但这种解决方法对我有用。
标签: ios ipad orientation