故事板方向支持xCode 4.2?

Ben*_*riu 13 iphone landscape storyboard device-orientation xcode4.2

我升级到了xCode 4.2,它是新的Storyboard功能.但是,找不到支持肖像和风景的方法.

当然,我是以编程方式完成的,有2个视图,一个用于纵向,一个用于横向,就像过去一样,并且:

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    {
        self.view = self.landscapeView;
    }
    else
    {
        self.view = self.portraitView;
    }
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一种方法,以某种方式自动执行此操作.我的意思是,现在是xCode 4.2,我期待更多.谢谢大家.

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

我将在这里提出一个临时解决方案.我说这是暂时的,因为我还在等苹果公司做一些非常聪明的事情.

我创建了另一个.storyboard文件,名为"MainStoryboard_iPhone_Landscape",并在那里实现了横向视图控制器.实际上,它与普通(肖像).storyboard完全一样,但所有屏幕都处于横向模式.

所以我将从横向故事板中提取ViewController,当轮换发生时,只需使用新的viewController视图更改self.view.

1.方向更改时生成通知:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)

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];
}];
Run Code Online (Sandbox Code Playgroud)

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];
 }}
Run Code Online (Sandbox Code Playgroud)

祝大家好运.

PS:我会接受Ad Taylor的答案,因为经过很长时间等待并寻找解决方案后,我最终实现了一些灵感来自他的答案.谢谢泰勒.

Ad *_*lor 6

这是一个古老的问题,但我在当天早些时候读过这个问题,然后不得不花费相当多的时间来制定更好的解决方案.我通过破解Apple Alternate View示例提出了这个解决方案.基本上它正在为景观视图提供模态视图.

#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);
}
Run Code Online (Sandbox Code Playgroud)