2011-03-14 85 views

回答

5

只需检查视图控制器的自动调整大小的属性。

(固定语法错误)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if(interfaceOrientation == UIInterfaceOrientationPortrait) 
     return YES; 

    return NO; 
} 
10

如果你想只需在应用程序的Info.plist文件停止整个应用程序旋转再改支持的接口方向初始界面取向财产为纵向或横向依赖on你

+0

这很容易和有用。有没有办法在一个视图控制器中覆盖它?我有10个视图控制器,其中一个需要在横向上,但其余的我用这种方法只限于纵向。 – PeonProgrammer 2015-02-27 18:13:06

+0

如果是这种情况,您必须重写方法 - (NSUInteger)supportedInterfaceOrientations { return __orientation; }在所有视图中控制器 – iOSPawan 2015-03-10 03:55:05

-3

我强烈建议不要在iPad上停止旋转,因为支持旋转是iPad上必须的。这是因为iPad不像通常以纵向视图(AKA Vertical)保存的iPhone那样采用正常的方式。因此,您必须将选择留给用户以最终锁定方向

HIG实际上并未将此作为要求声明,但作为建议,但有许多应用程序被此问题拒绝。

通过,如果你想这对于限制数视图控制器应实现方式:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if(interfaceOrientation == UIInterfaceOrientationPortrait){ 
     return YES; 
    } 
} 
5

在iOS6的shouldAutorotateToInterfaceOrientation已被弃用。改为覆盖supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation

Please see

+0

您的[请参阅](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixApresentedApirecatedAPI.html#//apple_ref/occ/instm/ UIViewController/shouldAutorotateToInterfaceOrientation%3a)链接不再有效 – dumbledad 2016-02-22 11:54:37

0

全球可控旋转锁定的主要思想是写包含锁定机构对每个视图控制器的UIViewController类别。

你只需要修改supportedInterfaceOrientations方法进行了全局

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return __orientation; 
} 

这里__orientation是可以通过类的方法来设置静态变量。

完全实现的类别呈现here

0

请更新您的projectname.plist这样。支持的接口方向只有一个对象“肖像(下home键)”

1

在我的项目的info.plist我已经删除了在iPad上Supported interface orientations像下面的图片的一些关键(我只给出了纵向支持)

enter image description here