2

这是我的问题:我的应用程序有一个工具栏,您可以在其中更改视图。主要的或至少启动时的一个处于横向模式,然后如果您转到任何其他视图,则处于纵向。当您尝试返回第一个(风景)时出现问题,视图以纵向显示,因此所有视图都显示错误。(它或多或少清楚吗?对不起,如果看起来很乱)。我在这里有一些代码:

V1控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

V2控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction)goToV1 {
 V1Controller *v1 = [[V1Controller alloc] init];
 [self.view.superview addSubview:v1.view];
}

也许在添加视图之前对对象 v1 做一些事情?我不知道,需要你的帮助。

问题已解决 在视图转换中我错过了一句话,从超级视图中删除当前视图。还有@Brad 在说什么。谢谢你。

-(IBAction)goToV1 {
     V1Controller *v1 = [[V1Controller alloc] init];
     [self.view.superview addSubview:v1.view];
     [self.view removeFromSuperview];
    }
4

1 回答 1

4

当你说:

return (interfaceOrientation == UIInterfaceOrientationPortrait);

您只允许将其旋转为纵向。

如果要旋转到纵向然后再返回横向,只需返回“YES”。

当您说时,同样的逻辑适用

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

您实际上是在说:“让它以一种方式旋转 - 但永远不要以另一种方式旋转”

于 2010-11-10T22:47:38.357 回答