简体   繁体   English

在ios7 / Xcode 5中将方向锁定为横向

[英]Lock Orientation to Landscape Right in ios7 / Xcode 5

I am aware that this questions has been asked before but Im yet to find a solution. 我知道之前曾有人问过这个问题,但我尚未找到解决方案。 In Xcode 5 i would like to lock my application to landscape right. 在Xcode 5中,我想将我的应用程序锁定为横向。 Here are the steps i have taken to set up the project. 这是我设置项目所采取的步骤。

(1) Create a Single View project (1)创建一个单视图项目

(2) Set Device Orientation to Landscape Right under the general settings tab (2)在常规设置标签下将设备方向设置为横向

(3) Set the View Controller Orientation to Landscape in main.storyboard (3)在main.storyboard中将View Controller Orientation设置为Landscape。

(4) Add the following code to ViewController.m (4)将以下代码添加到ViewController.m

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}

-(NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

(5) Add the following code to ViewController viewdidLoad (5)将以下代码添加到ViewController viewdidLoad

NSLog(@"frame %f %f", self.view.frame.size.width, self.view.frame.size.height);

Every time i run the app my view is 320 x 568 每次我运行该应用程序时,我的视野都是320 x 568

What do i need to set to get the view in landscape (568 x 320). 我需要设置什么才能获得风景(568 x 320)。

Thank you. 谢谢。

Even though device changed to landscape mode the width and height of the device/view is going to be same and it always returns the 320 x 568. 即使设备更改为横向模式,设备/视图的宽度和高度也将相同,并且始终返回320 x 568。

The difference is user viewing the device in landscape. 区别在于用户可以横向查看设备。 It will not give you the change in width and height as you expected. 它不会为您提供预期的宽度和高度变化。 !! !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM