Set orientation to landscape mode in xcode 4.5 GM IOS 6(在 xcode 4.5 GM IOS 6 中将方向设置为横向模式)
问题描述
我使用游戏中心开发了 IOS 5 应用程序.现在我希望我的代码在 IOS 6 上运行.所以我让我的应用程序同时支持方向,即横向和纵向,以便在弹出游戏中心登录屏幕时它不会崩溃.但在那之后,我的主视图控制器不会以横向视图启动.相反,当我进入更远的视图时,它以横向打开,然后当我回来时,主视图以横向打开.但是主页视图第一次没有打开横向模式.
I developed IOS 5 application using game center. Now I want my code to run on IOS 6. So I have let my application to support both orientation i.e landscape and portrait so that it does not crashes when game center login screen pops up. But after that, my home view controller does not starts in landscape view. Instead when I go to a further view, it opens in landscape, and then when i come back, then the home view opens in landscape. But home view does not opens to landscape mode for the first time.
代码如下:
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
这些是我在 IOS 6 的主页视图中使用的代表.
These are the delegates I use in home view for IOS 6.
推荐答案
在您的应用委托中添加此方法以支持 IOS 6 所需的方向..
Add this method in your app delegate to support desired orientation for IOS 6..
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskAll;
else /* iphone */
return UIInterfaceOrientationMaskAllButUpsideDown;
}
并在 IOS 6 的其他类中使用这些 delegates 进行定向.
and use these delagates for orientation in rest of clases for IOS 6.
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
这篇关于在 xcode 4.5 GM IOS 6 中将方向设置为横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 xcode 4.5 GM IOS 6 中将方向设置为横向模式


基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01