强制iOS应用程序在横向模式下启动
我正在为iOS 5开发一个应用程序,它必须以横向模式运行。我的问题是,我不能让它翻转。强制iOS应用程序在横向模式下启动
我曾尝试加入“初始界面方向”设置为“风景(右home键)” 并添加下面的方法来我的视图控制器:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
我可以环绕它如何我的头应该工作。 (我发现代码here)
我也想知道如何使用Xcode 4.2项目设置中提供的“支持的设备方向”,它似乎没有做任何事情。
我一直在寻找的网站和各地一直没能找到解决我的问题的例子。
谢谢。
在您的应用程序的Info.plist文件中,添加UIInterfaceOrientation
键并将其值设置为 横向模式。对于横向 方位,您可以将此密钥的值设置为 UIInterfaceOrientationLandscapeLeft
或 UIInterfaceOrientationLandscapeRight
。
铺陈在横向模式下您的意见,并确保他们的自动尺寸选项设置正确。
覆盖您的视图控制器的shouldAutorotateToInterfaceOrientation:
方法,并仅为 所需的横向方向返回YES,对于纵向方向返回YES 。
谢谢。 我的确如你所描述的那样做了。我有更多然后一个子视图,发现我必须覆盖所有控制器上的方法之前,我得到它的工作。 – bvd
如果您的info.plist你把UIInterfaceOrientationLandscapeRight其他景观上方,然后你就可以开始你的景观 –
我认为,如果你在项目支持的接口方向的plist它会工作。只需添加一个名为“支持的接口方向”的新行,并将其设置为数组类型,并为每个想要的景观视图添加2个项目。没有测试过这只是一个快速猜测
我曾尝试与没有运气。 – bvd
当你在XCode中点击你的项目的名称,并选择在目标与您的目标,摘要选项卡下有支持的设备方向设置的可视化表示。这就是我设法做到的。
试试这个,这将帮助你,你viewDidLoad中编写代码。
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
的UIDevice setOrientation应用程序是只读的,不能进行设置。 –
只读属性没有setter。 – SyntheticMeshwork
使用的appDelegate以下
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
还设置所需的方位
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
//Here are some iOS6 apis, used to handle orientations.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0)
- (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
shouldAutorotateToInterfaceOrientation:不叫帮我的赞赏 –
@JigPatel使用一些在iOS6的这些新方法' - (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) - (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation' – vishy
http://stackoverflow.com/a/17628668/468724 –