以不同方向改变视图
这是我的问题:我的应用程序有一个工具栏,您可以在其中切换视图。主要的视图或至少启动时的视图处于横向模式,然后如果您转到任何其他视图,则处于纵向模式。当您尝试返回第一个视图(横向)时,问题就出现了,视图以纵向显示,因此所有视图都显示错误。 (它或多或少清晰?抱歉,如果看起来很混乱)。我这里有一些代码:
V1Controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
V2Controller:
- (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];
}
Here's my issue: My app has a toolbar where you can change between views. The main one or at least the one on launch is in on landscape mode, then if you go to any other view is in portrait. The problem comes when you try to go back to the first one (landscape), the view appears in portrait, therefore all view is wrong displayed. (Is it more or less clear? sorry if seems messy). Some code I have here:
V1Controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
V2Controller:
- (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];
}
Maybe do something with the object v1 before adding the view? I don't know, need your help.
Problem solved
In the view transition I was missing one sentence, remove the current view from the superview. Also what @Brad was saying. Thank you.
-(IBAction)goToV1 {
V1Controller *v1 = [[V1Controller alloc] init];
[self.view.superview addSubview:v1.view];
[self.view removeFromSuperview];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您说:
您只允许将其旋转为纵向。
如果您想旋转到纵向然后再旋转到横向,只需返回“YES”即可。
时,同样的逻辑也适用。
当您说“您实际上是在说:“让它以一种方式旋转 - 但绝不以另一种方式旋转”
When you say:
Your are allowing it to be rotated only to portrait.
If you want to rotate to portrait and then back to landscape, just return "YES".
The same logic applies when you say
You are effectively saying: "Let it be rotated one way - but never back the other way"