Iphone开发:有什么方法可以在运行时锁定方向?

问题描述:

我需要一个既可以在纵向和landscape.But显示当我加载另一种看法,我只希望它显示景观的视图。Iphone开发:有什么方法可以在运行时锁定方向?

我有一个视图控制器A.which可以纵向地示出和landscape.This查看控制器由应用程序委托创建。

当我点击视图A.I一个按钮来创建,我想仅在显示landscape.and加载等[A.view addSubView:B.view]视图的视图控制器B。

当我旋转设备的功能shouldAutorotateToInterfaceOrientation仅在
控制器A.我如何设置控制器的功能B.It不能称之为叫不管。

关于第一个视图,确保

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

而且在你的第二个观点将其设置为

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

更新: 好吧,试试这个...
在你的主视图控制器/应用程序的委托,其中shouldAutorotateToInterfaceOrientation运行每次设备旋转时,把一个全局级别的变量。像

.h 
@interface NavAppDelegate : NSObject <UIApplicationDelegate> { 
    Bool *isMain; 
} 

.m 
-(void)viewDidLoad { 
    isMain = Yes; 
} 
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { 
    if (isMain) { 
     return Yes; 
    } else { 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
    } 
} 
// This bit is where you'll have to adapt it to how you change your views 
// but it's a basic idea. 
-(void)bitThatDoesTheViewChange:(viewController *) controller { 
    isMain = No; 

    *viewController = controller; 

    [viewController release]; 

    isMain = Yes; 
} 
+0

我想我已经设置在第二view.But功能就不能called.I认为只有视图控制器是由应用程序的委托创建可覆盖功能 – joe

+0

平添了几分更多,可能会帮助你的问题...我的ObjectiveC有点生疏,但我认为这应该工作。 – AndyD273

+0

这是改成了允许左,右横一个好主意 – joe