我看到很多关于这个问题的问题,但我无法找到解决我遇到的问题的方法。我创建了一个iPad应用程序,它应该只是Landscape - 它在iOS6之前的任何操作系统上运行时工作正常但在iOS6上应用程序以纵向视图打开。此屏幕截图显示了我的意思(抱歉,这不是一个很好的解释)http://s1342.beta.photobucket.com/user/designedbyria/media/ScreenShot2012-11-02at122113.png.html
我猜测问题出现在下面的代码中,但我无法确定。我已将支持的界面方向设置为仅横向左侧和横向右侧 - 但这不起作用。我也在这里看了一些没有运气的问题..
我正在使用xcode和cordova / phonegap
Interface orientation in iOS 6.0
Set orientation to landscape mode in xcode 4.5 GM IOS 6
iOS 6 apps - how to deal with iPhone 5 screen size?
提前致谢!
/ ** *这是应用程序启动后的主要启动,视图和设置在此处设置。 (首选 - iOS4及以上版本) / - (BOOL)应用程序:(UIApplication )应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSURL * url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]; NSString * invokeString = nil;if (url && [url isKindOfClass:[NSURL class]]) { invokeString = [url absoluteString]; NSLog(@"iwill launchOptions = %@", url); } CGRect screenBounds = [[UIScreen mainScreen] bounds]; self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease]; self.window.autoresizesSubviews = YES; CGRect viewBounds = [[UIScreen mainScreen] applicationFrame]; self.viewController = [[[MainViewController alloc] init] autorelease]; self.viewController.useSplashScreen = YES; self.viewController.wwwFolderName = @"www"; self.viewController.startPage = @"index.html"; self.viewController.invokeString = invokeString; self.viewController.view.frame = viewBounds; // check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation BOOL forceStartupRotation = YES; UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation]; if (UIDeviceOrientationUnknown == UIInterfaceOrientationLandscapeLeft) { // UIDevice isn't firing orientation notifications yet… go look at the status bar curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]; } if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) { for (NSNumber *orient in self.viewController.supportedOrientations) { if ([orient intValue] == curDevOrientation) { forceStartupRotation = YES; break; } } } if (forceStartupRotation) { NSLog(@"supportedOrientations: %@", self.viewController.supportedOrientations); // The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait) UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0]
的intValue]; NSLog(@“AppDelegate强制状态栏:%d来自:%d”,newOrient,curDevOrientation); [[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
} [self.window addSubview:self.viewController.view]; [self.window makeKeyAndVisible]; return YES; }
答案 0 :(得分:3)
我遇到了同样的问题(但没有使用cordova / phonegap)。
您必须将视图控制器设置为appDelegate中的RootViewController,而不是仅仅添加为子视图。
替换你的appdelegate:
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
通过
[self.window setRootViewController:self.viewController];
[self.window makeKeyAndVisible];
答案 1 :(得分:0)
您可以使用代理
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
使用此委托,应用程序将以横向模式或任何所需的方向模式显示。
试试吧。