我升级到Xcode 4.2,并且是新的故事板功能。但是,找不到支持肖像和景观的方法。

当然,我以编程方式做到了这一点,有2个观看次数,一个用于肖像,一个用于景观,例如在过去,以及:

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    {
        self.view = self.landscapeView;
    }
    else
    {
        self.view = self.portraitView;
    }

但是我一直在寻找一种自动做到这一点的方法。我的意思是,现在是Xcode 4.2,我期望更多。谢谢大家。

==================================
临时解决方案:

我将在这里提出一个临时解决方案。我说这是暂时的,因为我仍在等待苹果家伙对此非常聪明。

我创建了另一个.Storyboard文件,称为“ Mainstoryboard_iphone_landscape”,并在那里实现了景观视图控制器。实际上,这完全像普通(肖像)。故事板,但所有屏幕都处于景观模式。

因此,我将从景观故事板上提取视图控制器,当旋转发生时,只需更改自我。查看新ViewController的视图即可。

1.何时定向发生变化时,会产生通知:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

2.通知查看:

[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {    
    // We must add a delay here, otherwise we'll swap in the new view  
    // too quickly and we'll get an animation glitch  
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}];

3.成像UpdateLandScapeView

- (void)updateLandscapeView {  
 //>     isShowingLandscapeView is declared in AppDelegate, so you won't need to declare it in each ViewController
 UIDeviceOrientation deviceOrientation       = [UIDevice currentDevice].orientation;
 if (UIDeviceOrientationIsLandscape(deviceOrientation) && !appDelegate().isShowingLandscapeView)
 {
     UIStoryboard *storyboard                = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_Landscape" bundle:[NSBundle mainBundle]];
     MDBLogin *loginVC_landscape             =  [storyboard instantiateViewControllerWithIdentifier:@"MDBLogin"];
     appDelegate().isShowingLandscapeView    = YES;  
     [UIView transitionWithView:loginVC_landscape.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
         //>     Setup self.view to be the landscape view
         self.view = loginVC_landscape.view;
     } completion:NULL];
 }
 else if (UIDeviceOrientationIsPortrait(deviceOrientation) && appDelegate().isShowingLandscapeView)
 {
     UIStoryboard *storyboard                = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
     MDBLogin *loginVC                       = [storyboard instantiateViewControllerWithIdentifier:@"MDBLogin"];
     appDelegate().isShowingLandscapeView    = NO;
     [UIView transitionWithView:loginVC.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
         //>     Setup self.view to be now the previous portrait view
         self.view = loginVC.view;
     } completion:NULL];
 }}

祝大家好运。

PS:我会接受Ad Taylor的答案,因为在等待和寻找解决方案之后,我完成了从他的答案中启发的东西。谢谢泰勒。

有帮助吗?

解决方案

这是一个古老的问题,但我在当天早些时候阅读了这篇文章,然后不得不花费大量时间来解决更好的解决方案。我想出了这个解决方案 苹果替代查看示例. 。基本上,它可以为景观视图提供模态视图。

#pragma mark Rotation view control

- (void)orientationChanged:(NSNotification *)notification
{
    // We must add a delay here, otherwise we'll swap in the new view
    // too quickly and we'll get an animation glitch
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !self.isShowingLandscapeView)
    {
        [self performSegueWithIdentifier: @"toLandscape" sender: self];
        self.isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && self.isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        self.isShowingLandscapeView = NO;
    }    
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

其他提示

通常,您不应该考虑不同方向的单独观点,除非它们有很大差异(可以说,它们不应该是)。相反,您应该依靠 自动化口罩 在监督框架更改时,基于基本限制来列出视图的内容的大部分内容。这将使子视图通常由于接口方向更改而适当响应其监督框架的更改。

为了更直接地回答您的问题,不,Xcode无法假设或被告知您要用于特定界面取向的观点,因为这从来都不是的意图 UIKit的视图架构。

这是有关自动面罩的更多信息: 使用自动化规则自动处理布局更改.

在Xcode v4.2.1中使用故事板时,您只能更改视图控制器的方向,而不能更改视图本身,因此,如果您插入了另一个视图正确查看。

因此,使用故事板时,以前的有两个视图的方法似乎不起作用(使用NIB的视图方向可更改为单独视图的位置)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top