iOS旋转带UITabBarController-完全平稳地将控制器切换到外部
我有一个iOS应用程序,故事板的主要入口是一个带有选项卡的选项卡栏。我想支持旋转,但在横向模式下,每个选项卡看起来都会有很大的不同,以至于我需要从故事板上与其他选项卡一起更改视图。起初,我考虑在用户旋转时关闭整个选项卡栏控制器,但我不知道如何实现。因此,我有两个选择,我似乎无法与任何地方iOS旋转带UITabBarController-完全平稳地将控制器切换到外部,ios,objective-c,uitabbarcontroller,uiinterfaceorientation,screen-rotation,Ios,Objective C,Uitabbarcontroller,Uiinterfaceorientation,Screen Rotation,我有一个iOS应用程序,故事板的主要入口是一个带有选项卡的选项卡栏。我想支持旋转,但在横向模式下,每个选项卡看起来都会有很大的不同,以至于我需要从故事板上与其他选项卡一起更改视图。起初,我考虑在用户旋转时关闭整个选项卡栏控制器,但我不知道如何实现。因此,我有两个选择,我似乎无法与任何地方 以某种方式将每个视图切换到其景观备选方案,然后再切换回来。我见过使用模态视图很容易做到这一点,但以前没有使用uitabar 以某种方式从代理中切换出整个选项卡栏,这样我的故事板就有了两个完全独立的部分,除了一个
有没有人做过类似的事情,可以扔我一根骨头 您可以为两个视图控制器创建自定义类,将它们与segoes链接在一起,然后使用
didRotateFromInterfaceOrientation:
从代码触发segues。
为你的VC创建一个类。将此代码添加到.m
文件:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self performSegueWithIdentifier:@"rotateToPortrait" sender:nil];
} else {
[self performSegueWithIdentifier:@"rotateToLandscape" sender:nil];
}
}
在故事板中,在两个视图之间创建分段。将其标识符分别设置为“RotateToartic”和“RotateToarth”。您添加的代码将在设备旋转时切换视图
编辑:我想我误解了这个问题。如果要在旋转屏幕时移动视图、更改其大小等,同时保持相同的导航/选项卡栏状态,则可以在didRotateFromInterfaceOrientation
方法中执行类似操作:
if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
myView.frame.origin.x = aNumber;
myView.frame.size.width = anotherNumber;
// Changing the layout of the views here by resetting their origins and sizes.
// This code is called when rotated from portrait to landscape.
} else {
// Do the same thing as above, but this one handles rotation from landscape to portrait.
}
等待我不认为这回答了这个问题。。。你能用上面的方法重新排列视图吗?是的,我也不确定这是否能回答这个问题。这确实是一个很好的答案,但既然您在故事板中的TabViewController中,那么segue转换是什么样子的呢?如何链接视图?嗯,我认为segue没有过渡,并且会在旋转时切换视图。您可以将视图链接到手动分段,这些分段由自定义类自动触发。我将用更多信息更新我的答案。