简体   繁体   English

我可以在iPhone和iPad(纵向和横向)上使用单独的故事板吗?

[英]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: 如果您想要其他故事板,则可以在主视图控制器中尝试以下代码:

Obj-C 对象

- (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
}

Swift 迅速

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.

相关问题 应用程序可以自动从iPad上的肖像旋转到风景,但不能在iPhone上 - App can auto rotate to landscape from portrait on iPad but not on iPhone 如何在Adobe AIR应用程序中强制iPad中的横向和iPhone中的纵向? - How can i force landscape in iPad and portrait in iPhone in an Adobe AIR app? Ipad在横向模式下和iphone在纵向模式下 - Ipad in landscape mode and iphone in portrait mode 启动应用程序Iphone纵向和Ipad横向 - Launch app Iphone portrait, and Ipad landscape iPhone / iPad视点在纵向和横向上发生变化 - iPhone/iPad viewpoint changes on portrait and landscape 我应该使用尺寸类别移植到iPad还是创建单独的故事板? - Should I use size classes to port to iPad or create separate storyboards? 支持iPhone上的纵向方向的通用应用程序和iPad上的横向+纵向 - Supporting Universal App with Portrait Orientation on iPhone and Landscape+Portrait on iPad 为iPhone创建单独的纵向和横向布局 - Create Separate Portrait and Landscape Layouts for iPhone SwiftUI:仅在 iPhone 上显示纵向视图,但在 iPad 上显示纵向和横向 - SwiftUI: Make View portrait only on the iPhone, but both portrait and landscape on the iPad iPad兼容模式下的iPhone应用程序在横向上有奇怪的布局(我强迫肖像) - iPhone app on iPad compatibility mode has strange layout in landscape (while I force portrait)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM