简体   繁体   中英

iOS - Change view when orientation changes

I use iOS5 with storyboards, I created two ViewController, one for the portrait orientation and one for the landscape.. I connected the two views with two "modal segue" and this is the code that I used:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
    [self performSegueWithIdentifier: @"aaaa" sender: self];
}
else if (deviceOrientation == UIDeviceOrientationPortrait)
{
    [self performSegueWithIdentifier: @"ddd" sender: self];
}    

return true;

}

If I change from portrait to landscape it works but when I return to portrait view it crashes with "has no segue with identifier 'ddd'" but it exists.

Thanks.

I have resolved setting a modal segue between the views and then into the implementation file with this code:

- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
   if(self.interfaceOrientation == UIDeviceOrientationPortrait || self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){

       [self performSegueWithIdentifier: @"aaaa" sender: self];

   } else  if(self.interfaceOrientation == UIDeviceOrientationLandscapeLeft || self.interfaceOrientation == UIDeviceOrientationLandscapeRight)
   {

       [self performSegueWithIdentifier: @"ddd" sender: self];
   }
}

Course for both the ViewController (portrait and landscape).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM