1

I am only allowing Device Orientation portrait for UIViewControllers being viewed on iPhones through the following code:

- (BOOL)shouldAutorotate
{
    NSString *device = [UIDevice currentDevice].model;
    return [device rangeOfString:@"iPhone"].location != NSNotFound ? NO : YES;
}

This works fine - when I rotate my iPhone while looking at ViewController A, the view does not rotate. Similarly, when I rotate my iPhone while looking at ViewController B, the view does not rotate. However, when I rotate my iPhone while looking at ViewController A, tap a button that presents ViewController B modally, the show segue animation (Flip Horizontal) is landscape, and ViewController B appears in landscape.

How can I force the segue to be portrait as well and not rotate ViewController B?

Josh Gafni
  • 2,831
  • 2
  • 19
  • 32
  • I don't think the Flip Horizontal segue works with a portrait layout. Try using a different segue. – saagarjha Sep 04 '15 at 04:01
  • no it works with portrait layout. if i do not rotate the device, it looks perfect. Also if I do not allow landscape mode via the target - it always looks fine, but I want to allow landscape on the iPad. – Josh Gafni Sep 04 '15 at 04:03
  • You can manually set the orientation when the segue appears ViewController B appears. – saagarjha Sep 04 '15 at 04:27
  • But the segue doesn't flip portrait... it flips landscape, which does not look right. – Josh Gafni Sep 04 '15 at 04:28
  • Have you tried creating your own custom segue? There you should be able to define which orientation to use. http://stackoverflow.com/questions/13010655 – Beau Nouvelle Sep 04 '15 at 04:46
  • Yeah, I don't want to create a custom segue if i'm using one of Apple's prebuilt ones. If I was trying to create a different animation completely I would do that. – Josh Gafni Sep 04 '15 at 04:47

1 Answers1

0

In my tests I've found that shouldAutorotate is only one part of the things you have to do to prevent rotation of the device. shouldAutorotate tells the system if it should rotate all the views as soon as someone rotates the device to a different allowed orientation.

My suggestion would be to prevent more orientations other than Landscape (which allows LandscapeLeft and LandscapeRight). And by that I mean you should override supportedInterfaceOrientations in both ViewControllers and tell the app that it should only allow landscape orientations instead of the default (which allows all but upside-down orientation).

RoberRM
  • 883
  • 9
  • 18