如何在横向方向上推出通用的Xcode 5 app项目? [英] How to make universal Xcode 5 app project launch in landscape orientation?
问题描述
我创建了一个单一视图应用程序项目,并设置了所有选项以启动并仅支持横向。但应用程序以纵向方向启动窗口。
I created a "Single View Application" project and set all options to launch and support only landscape orientation. But the app launches with its window in portrait orientation.
控制台输出显示应用程序后面的窗口:didFinishLaunchingWithOptions:
是:
{{0, 0}, {768, 1024}}
我添加了一个标准系统按钮来查看ViewController,以说明应用程序是横向而非纵向,但窗口是纵向的。
I added a standard system button to view of ViewController to illustrate that the app is landscape and not portrait, but that the window is portrait.
因为堆栈溢出有白色背景我在Photoshop中将右边的部分变成灰色,所以你可以看到它:
Because stack overflow has white background I colored the right part gray in Photoshop so you can see it:
在应用程序中: didFinishLaunchingWithOptions:
我将窗口涂成红色。它显然不是横向的。
In application:didFinishLaunchingWithOptions:
I colored the window red. It is clearly not in landscape orientation.
我已经尝试了我所知道的所有技巧:
I have tried all the tricks I know:
1)信息.plist包含UISupportedInterfaceOrientations键,其中包含:
UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight
1) Info.plist contains UISupportedInterfaceOrientations key with: UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight
2)Info.plist包含UISupportedInterfaceOrientations~ipad键:
UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight
2) Info.plist contains UISupportedInterfaceOrientations~ipad key with: UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight
3)Info.plist包含初始界面方向的UIInterfaceOrientation键:
UIInterfaceOrientationLandscapeRight
3) Info.plist contains UIInterfaceOrientation key for initial interface orientation: UIInterfaceOrientationLandscapeRight
4)点击Xcode中的项目然后取消选中所有肖像选项,只检查横向选项:
4) Clicked on the project in Xcode and then unchecked all portrait options and only checked the landscape options:
5)AppDelegate和ViewController都有:
5) AppDelegate and the ViewController both have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
6)AppDelegate有:
6) AppDelegate has:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Xcode创建了两个故事板文件。我现在只在iPad上测试。一个是Main_iPad.storyboard,它显示了一个纵向的视图控制器。但它只是一个模拟的界面指标。更改为横向并且预期无效。
Xcode created two storyboard files. I am only testing on iPad right now. One is Main_iPad.storyboard and it shows a view controller which was in portrait. But it was only a simulated interface metric. Changed to landscape and as expected no effect.
在应用程序启动期间,我检查UIScreen边界,它也显然是肖像,而不是横向:
During app launch I check UIScreen bounds and it also is clearly portrait, not landscape:
CGRect screenBounds = [[UIScreen mainScreen] bounds]; // {{0, 0}, {768, 1024}}
如何启动它在横向和横向创建一个窗口?
How can I make it launch in landscape and create a window in landscape orientation?
推荐答案
我之前遇到过类似的问题,所以也许他们有关系.. 。
I had a similar problem before, so maybe they're related...
我遇到了问题,因为我在视图控制器的 initWithNibName:bundle:
中以编程方式创建视图无论出于何种原因,在应用程序的其余部分运行横向时,这样做会以纵向模式定向新视图。
I had a problem because I was creating my view programmatically in my view controller's initWithNibName:bundle:
and for whatever reason, doing so orients the new view in portrait mode while the rest of the app is running landscape.
我发现了两个针对此问题的修复程序。 1)使用故事板而不是以编程方式创建视图或2)移动代码以从视图控制器的 initWithNibName:bundle:
方法创建视图并将其放在视图控制器中 -viewDidLoad:
这样的方法:
I found two fixes for this problem. 1) Create the view using your storyboard instead of programmatically or 2) move the code to create the view from your view controller's initWithNibName:bundle:
method and place it in the view controller's -viewDidLoad:
method like this:
-(void)viewDidLoad {
//Create your view programmatically
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
//Customize view
[self.view addSubview:view];
}
这是我遇到类似问题的解决方案。虽然我认识到有很多方法可以让程序员无法正常工作,但我希望这就是答案!
That was the solution for a similar problem I had. While I recognize that there's a myriad of ways that we programmers can make things not work the right way, I hope this is the answer!
这篇关于如何在横向方向上推出通用的Xcode 5 app项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!