2010-11-10 62 views
2

这是我的问题:我的应用程序有一个工具栏,您可以在视图之间切换。主要的一个或至少一个发布是在横向模式,然后如果你去任何其他视图是肖像。当您尝试返回到第一个(横向)时,问题就出现了,视图以纵向显示,因此所有视图均显示错误。 (是否或多或少清楚?对不起,如果似乎凌乱)。一些代码,我这里有:以不同的方向更改视图

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的东西添加视图之前?我不知道,需要你的帮助。

问题解决 在视图转换中,我错过了一个句子,从超级视图中删除当前视图。还有@布拉德在说什么。谢谢。

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

回答

4

当你说:

return (interfaceOrientation == UIInterfaceOrientationPortrait); 

你被允许它旋转只肖像。

如果你想旋转肖像,然后返回到风景,只需返回“是”。

同样的逻辑也适用于当你说

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 

你实际上是说:“让它旋转的一种方式 - 但从未回来的其他方式”

+0

我有两个观点,就像你说,回来是。在界面生成器中,V1处于横向,V2处于纵向。同样在info.plist上,初始方向设置为UIInterfaceOrientationLandscapeLeft。从V2→V1时仍然无法工作。 – framara 2010-11-11 08:38:40

相关问题