【问题标题】:Changing view with different orientation以不同的方向改变视图
【发布时间】:2010-11-10 22:25:07
【问题描述】:

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

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];
    }

【问题讨论】:

    标签: iphone objective-c orientation uiinterfaceorientation


    【解决方案1】:

    当你说:

    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    

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

    如果您想旋转到纵向然后返回到横向,只需返回“YES”即可。

    同样的道理也适用于你说

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    

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

    【讨论】:

    • 我有两种观点,就像你说的,返回是。在界面生成器中,V1 为横向,V2 为纵向。同样在 info.plist 上,初始方向设置为 UIInterfaceOrientationLandscapeLeft。从 V2 -> V1 开始时仍然无法正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多