0

I have separate landscape and portrait views in iOS7 using the code below:

-(void)didRotateFromInterfaceOrientation:    (UIInterfaceOrientation)fromInterfaceOrientation {
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {

    CGRect currentBounds=self.view.bounds;

    if (iPadInt==0) {
        if (self.interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
            self.view=self.landscapeQuestionView;
            self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(90));
        } else if (self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
            self.view=self.landscapeQuestionView;
            self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(-90));
        } else if (self.interfaceOrientation==UIInterfaceOrientationPortrait) {
            self.view=self.portraitQuestionView;
            self.view.transform=CGAffineTransformMakeRotation(0);
        } else if (self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
            self.view=self.portraitQuestionView;
            self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(180));
        } self.view.bounds=currentBounds;
    } else if (iPadInt==1) {
        if (self.interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
            self.view=self.iPadLandscapeQuestionView;
            self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(90));
        rotationInt=90;
        } else if (self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
            self.view=self.iPadLandscapeQuestionView;
            self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(-90));
             rotationInt=90;
        } else if (self.interfaceOrientation==UIInterfaceOrientationPortrait) {
            self.view=self.iPadPortraitQuestionView;
            self.view.transform=CGAffineTransformMakeRotation(0);
            rotationInt=0;
        } else if (self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
            self.view=self.iPadPortraitQuestionView;
            self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(180));
            rotationInt=0;
        } self.view.bounds=currentBounds;
    }
}

I know I should use the viewWillTransitionToSize method in iOS8, but I can't figure out how to get these different views in that method. Thanks in advance for any help.

Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
Allison
  • 171
  • 1
  • 1
  • 6

1 Answers1

0

There is a topic here: Rotation methods deprecated, equivalent of 'didRotateFromInterfaceOrientation'?

I think in your situation you can use viewWillTransitionToSize: like this:

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
     {
         //get orientation
         UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
         //check orientation
         if (orientation==UIInterfaceOrientationPortrait)
         {
             NSLog(@"portrait");
         }
         else if(orientation==UIInterfaceOrientationPortraitUpsideDown)
         {
             NSLog(@"upside-down");
         }
         else if(orientation==UIInterfaceOrientationLandscapeRight)
         {
             NSLog(@"landscape right");
         }
         else if(orientation==UIInterfaceOrientationLandscapeLeft)
         {
             NSLog(@"landscape left");
         }
     } completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
     {

     }];
}
Community
  • 1
  • 1
EFE
  • 3,732
  • 4
  • 22
  • 30