Ios Iphone开发:有没有办法在运行时锁定方向?

Ios Iphone开发:有没有办法在运行时锁定方向?,ios,ios4,Ios,Ios4,我需要一个视图,可以显示在纵向和横向。但当我加载另一个视图时,我只希望它显示在横向 我有一个视图控制器a,可以纵向和横向显示。这个视图控制器是由应用程序代理创建的 当我单击视图a上的按钮时,我创建了一个视图控制器B,我只想在横向视图中显示它,并像[a.view addSubView:B.view]那样加载视图 旋转设备时,仅在 控制器A。无论我如何设置控制器B中的函数。都无法调用它。在第一次查看时,请确保 -(BOOL)shouldAutorotateToInterfaceOrientation

我需要一个视图,可以显示在纵向和横向。但当我加载另一个视图时,我只希望它显示在横向

我有一个视图控制器a,可以纵向和横向显示。这个视图控制器是由应用程序代理创建的

当我单击视图a上的按钮时,我创建了一个视图控制器B,我只想在横向视图中显示它,并像[a.view addSubView:B.view]那样加载视图

旋转设备时,仅在

控制器A。无论我如何设置控制器B中的函数。都无法调用它。

在第一次查看时,请确保

-(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;
}
.h
@接口NavAppDelegate:NSObject{
布尔*伊斯曼;
}
M
-(无效)viewDidLoad{
伊斯曼=是;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
如果(伊斯曼){
返回Yes;
}否则{
返回(interfaceOrientation==UIInterfaceOrientationAndscapeLeft | | interfaceOrientation==UIInterfaceOrientationAndscapeRight);
}
}
//这一点是你必须调整它以适应你改变观点的方式
//但这是一个基本的想法。
-(void)执行视图更改的位:(viewController*)控制器{
伊斯曼=否;
*视图控制器=控制器;
[视图控制器释放];
伊斯曼=是;
}

在第一次查看时,请确保

-(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;
}
.h
@接口NavAppDelegate:NSObject{
布尔*伊斯曼;
}
M
-(无效)viewDidLoad{
伊斯曼=是;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
如果(伊斯曼){
返回Yes;
}否则{
返回(interfaceOrientation==UIInterfaceOrientationAndscapeLeft | | interfaceOrientation==UIInterfaceOrientationAndscapeRight);
}
}
//这一点是你必须调整它以适应你改变观点的方式
//但这是一个基本的想法。
-(void)执行视图更改的位:(viewController*)控制器{
伊斯曼=否;
*视图控制器=控制器;
[视图控制器释放];
伊斯曼=是;
}

我想我已经在第二个视图中设置了该函数。但是无法调用它。我认为只有由应用程序委托创建的视图控制器才能覆盖更多的函数,这可能有助于解决您的问题。。。我的ObjectiveC有点生锈,但我认为这应该可以工作。我认为我已经在第二个视图中设置了该函数。但无法调用它。我认为只有由应用程序委托创建的视图控制器可以覆盖更多的函数,这可能会帮助解决您的问题。。。我的ObjectiveC有点生锈,但我认为这应该行得通。