Storyboards orientation support for xCode 4.2?

前端 未结 3 1863
清歌不尽
清歌不尽 2020-12-15 08:21

I upgraded to xCode 4.2 and it\'s new Storyboards feature. However, could not find a way to support both portrait and landscape.

Of course, I did it programmatically

3条回答
  •  醉酒成梦
    2020-12-15 09:03

    This is an old question but I read this earlier in the day and then had to spend a fair amount of time work out a better solution. I came up with this solution from hacking up the Apple Alternate View example. Basically it is serving up a modal view for the landscape 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);
    }
    

提交回复
热议问题