这是我的问题:我的应用程序有一个工具栏,您可以在其中切换 View 。主要的 View 或至少启动时的 View 处于横向模式,然后如果您转到任何其他 View ,则处于纵向模式。当您尝试返回第一个 View (横向)时,问题就出现了, View 以纵向显示,因此所有 View 都显示错误。 (它或多或少清晰?抱歉,如果看起来很困惑)。我这里有一些代码:
V1 Controller :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
V2 Controller :
- (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];
}
也许在添加 View 之前对对象 v1 做一些事情?我不知道,需要你的帮助。
问题已解决 在 View 转换中我漏掉了一句话,从 super View 中删除当前 View 。还有@Brad 所说的。谢谢。
-(IBAction)goToV1 {
V1Controller *v1 = [[V1Controller alloc] init];
[self.view.superview addSubview:v1.view];
[self.view removeFromSuperview];
}
最佳答案
当你说:
return (interfaceOrientation == UIInterfaceOrientationPortrait);
您只允许将其旋转为纵向。
如果您想旋转到纵向然后再旋转到横向,只需返回“YES”即可。
当你说时,同样的逻辑也适用
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
您实际上是在说:“让它以一种方式旋转 - 但绝不以另一种方式返回”
关于iphone - 以不同方向改变 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4149717/