iphone - 以不同方向改变 View

标签 iphone objective-c orientation uiinterfaceorientation

这是我的问题:我的应用程序有一个工具栏,您可以在其中切换 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/

相关文章:

ios - NSPredicate 检查以逗号分隔的一串数字是否包含数字

iphone - 在 iPhone 上将音频文件与 NSData 正确组合为一个

objective-c - 应用程序提交 iOS 的 Bundle ID

IOS:多个数组显示在单个 Tableview 上

android - 在 ImageView 中显示的从相机拍摄的照片始终是水平的 Android

iphone - 如何使用imageview在iphone中显示相册照片

iphone - UITabBarController 上的 AddSubView

objective-c - 如何让我的音乐循环播放(重复)

android - 来自画廊/相机 Intent 的图片方向

ios - 纵向模式下的快速视频裁剪