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 中将方向设置为横向模式
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
