问题描述
带有故事板的简单 iOS 应用程序 - StoryboardA
Simple iOS App with a storyboard - StoryboardA
当 iPad 改变方向时 - 我想加载一个新的故事板 - StoryboardB
When the iPad changes orientation - I would like to load a new storyboard - StoryboardB
我把那个逻辑放在哪里.
Where do I put that logic.
当横向(及其导航)的 UI 与纵向的 UI 不同时,这是一个好的做法吗.
Is this a good practice when the UI in landscape (and it's navigation) is different than in portrait.
推荐答案
您可以通过以下方式注册UIDeviceOrientationDidChangeNotification
You can register for UIDeviceOrientationDidChangeNotification in following way
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
在收到上述 UIDeviceOrientationDidChangeNotification 的通知后,您的orientationChanged: 方法将被触发,您可以在其中实现您想要实现的任何布局更改,如下所示:-
and on being notified of above mentioned UIDeviceOrientationDidChangeNotification, your orientationChanged: method will get fired, in which you can implement whatever layout changes you want to implement as follows:-
在您的私有界面 isShowingLandscapeView 中创建一个 BOOL 标志,以跟踪当前设备处于哪个方向并采取相应的行动
Create a BOOL flag in your private interface, isShowingLandscapeView, to keep track of which orientation currently device is on and act accordingly
BOOL isShowingLandscapeView = NO;
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
// Changes pertaining to lanscape orientation here
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
// Changes pertaining to portrait orientation here
isShowingLandscapeView = NO;
}
}
这篇关于iOS 加载新的故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!