[英]Can I use separate storyboards for iPhone and iPad(Portrait and Landscape)?
I am working on an app which supports iPhone and iPad. 我正在开发一个支持iPhone和iPad的应用程序。 For iPad we are supporting both portrait and landscape (iOS 9.0). 对于iPad,我们同时支持纵向和横向(iOS 9.0)。 But for some reason, to satisfy the requirement we have to maintain separate storyboards for landscape UI. 但是出于某种原因,为了满足要求,我们必须为景观UI维护单独的情节提要。 Is this accepeted by Apple. 这是Apple认可的吗?
Want to make sure that this is as per APPLE guidelines. 想要确保这符合APPLE准则。
If you want different storyboard you can try the following code in the main view controller: 如果您想要其他故事板,则可以在主视图控制器中尝试以下代码:
- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
NSString* storyboard = (size.width > size.height ) ? @"lanscape" : @"portrait";
UIStoryboard* mainView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
UIViewController* viewcontroller = [mainView instantiateInitialViewController]
// remove privious view controller
// add newViewcontroller
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
let storyboardName = (size.width > size.height ) ? "lanscape" : "portrait"
var mainView: UIStoryboard!
mainView = UIStoryboard(name: storyboardName, bundle: nil)
if let newViewcontroller : UIViewController = mainView.instantiateInitialViewController() {
// remove privious view controller
// add newViewcontroller
}
}
I hope it could help you. 希望对您有所帮助。
You can use two separate story boards for iPhone and iPad only if there's 2 orientations(Landscape and portrait) needed for iPad and the UI for each orientation changes drastically. 仅当iPad需要两个方向(横向和纵向)并且每个方向的UI发生巨大变化时,才可以为iPhone和iPad使用两个单独的故事板。 Since iPad's size class is Regular-Regular for both orientations you can still go ahead and build UI in one storyboard. 由于iPad的大小类别在两个方向上都是“常规-常规”,因此您仍然可以继续在一个情节提要中构建UI。
There can be situations where you cannot keep manipulating constraints or views for different orientations under same size class. 在某些情况下,您无法在相同尺寸级别下继续操纵不同方向的约束或视图。 It would become cumbersome and too complicated further. 这将变得麻烦并且进一步变得太复杂。
Hence its always a better idea to keep 2 storyboard (1 for another orientation of iPad) them separate if the UI for both orientation for iPad is different. 因此,如果iPad的两个方向的UI不同,则最好将2个故事板(对于iPad的另一个方向为1个)分开。
However for iPhone and for one of the orientaion of iPad you can still go ahead with 1 storyboard as they inherit different size classes. 但是,对于iPhone和iPad之一,您仍然可以继续使用1个故事板,因为它们继承了不同的大小类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.