简体   繁体   English

iOS:如何在情节提要中在横向和纵向视图之间切换?

[英]iOS: how to switch between landscape and portrait view in storyboard?

In my universal application I have a master detail at the beginning. 在我的通用应用程序中,一开始我有一个主要的细节。 On the iPad it is just shown as a split view and when I change the interface orientation the autosizing works fine. 在iPad上,它仅显示为拆分视图,当我更改界面方向时,自动调整大小效果很好。 But on the iPhone this doesn't work good enough in my detail view. 但是在iPhone上,这在我的详细信息视图中还不够好。 So I want to have two different views for my DetailViewController that should have the exact same functionality, but I can't really get it to work properly. 所以我想为我的DetailViewController使用两个不同的视图,这些视图应该具有完全相同的功能,但是我无法真正使其正常工作。 I tried to use two view controllers, but that didn't really do the job. 我尝试使用两个视图控制器,但实际上并没有完成任务。 I am using a storyboard by the way. 顺便说一下,我正在使用情节提要。

I thought I have found a solution by adding two views to my DetailViewController. 我以为我已经找到了一个解决方案,将两个视图添加到我的DetailViewController中。 Then I simply check the current orientation and set the recent view like this: 然后,我只需检查当前方向并像这样设置最近的视图:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    Video *currentVideo = [[self.xmlParser videos] objectAtIndex:indexPath.row];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        [self.detailViewController setDetailItem:currentVideo];
    else {

        if (!self.detailViewController) {

            DetailViewController *nextController = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
            if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait)
                [nextController setView:nextController.portraitView];
            else
                [nextController setView:nextController.landscapeView];
            [nextController setDetailItem:currentVideo];
            [self.navigationController pushViewController:nextController animated:YES];
        }        
    }
}

This works like it should, but now I face another problem. 这可以正常工作,但是现在我面临另一个问题。 The two views contain exactly the same outlets, but I can only connect the outlets of either one of them to my DetailViewController class. 这两个视图包含完全相同的插座,但是我只能将其中一个插座连接到我的DetailViewController类。 So in one of the orientations I can't view my contents properly or I have to code everything twice what is exactly the thing I want to avoid. 因此,在一种情况下,我无法正确查看内容,或者必须对所有内容进行两次编码,这正是我要避免的事情。

Do have any ideas how I could handle this problem? 有什么想法可以解决这个问题吗?

Thanks in advance 提前致谢

You can try adding two views inside a container view to the view controller in the Storyboard. 您可以尝试将容器视图内的两个视图添加到情节提要中的视图控制器。 Size one to be the portrait, the other - the landscape. 大小一个为人像,另一个为风景。 Add all the controls you need to whichever view required. 将所需的所有控件添加到所需的任何视图。 When the orientation changes - hide one and show the other. 当方向改变时-隐藏一个并显示另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS故事板限制/纵向和横向视图的特征 - iOS Storyboard Constraints/Traits for portrait and landscape view 如何在iOS中支持横向和纵向视图? - How to support landscape and portrait view in iOS? 如何在iOS 9上以横向和纵向模式显示iPad Launchscreen Storyboard? - How to display iPad Launchscreen Storyboard in landscape and portrait mode on iOS 9? 如何正确在Storyboard中的视图控制器之间进行手动切换(是iOS)? - How properly manually to switch between View Controllers in Storyboard (is iOS)? 纵向和横向故事板的替代iOS布局 - Alternative iOS layouts for portrait and landscape storyboard 自动布局IOS 7故事板强制横向或纵向 - Autolayout IOS 7 Storyboard Force Landscape or Portrait 从tabBar选择其他视图时,iOS5故事板的横向/纵向按钮位置/ iAd问题 - iOS5 Storyboard Landscape/Portrait button position/iAd issue when selecting different view from tabBar 如何在iOS中为横向和纵向视图创建单独的布局 - How to Create separate layout for landscape and portrait view in iOS 如何在iOS 6及更高版本中将单个视图从纵向旋转为横向? - How to rotate a single view from portrait to landscape in iOS 6 and above? 故事板中的横向和纵向方向 - Landscape and portrait orientation in storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM