Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ViewController does not respect UIInterfaceOrientation while statusBar does #469

pareshs44 opened this Issue Jan 28, 2014 · 3 comments


None yet
3 participants

If I m using IIViewDeckController with any view and in landscape mode presenting a modal viewController which supports only portrait orientation. After the modal view is dismissed the original viewController goes back in portrait orientation even when the device is in landscape orientation. All this time interfaceOrientation property correctly shows the interface orientation to be landscape. This itself is a problem that even though the interface orientation is landscape, the view is shown in portrait. But to add to it the statusBar notices its correct orientation and moves to its position in landscape mode. Thus the final view looks something like the picture shown.

As is clear from the above image that the view controller is still in its portrait position while the status bar has moved to its correct position and state, as it should be in landscape orientation.

This can always be reproduced given the above conditions. To demonstrate statusBar orientation change you can just add a alertView when the modal view is dismissed and when the alert is cancelled the status bar rotates to its position in landscape orientation.

same problem...

thx you ^^

The culprit here is preferredInterfaceOrientationForPresentation method in IIViewDeckController.m which does the right thing by delegating its call to the self.centerController and asking it for its preferredInterfaceOrientation. But here is an issue with that.

According to Apple documentation if a viewController does not implement its preferredInterfaceOrientationForPresentation method then any call to it returns the orientation based on the current position of the status bar. Now for cases like the one mentioned in the issue above, when the preferredInterfaceOrientationForPresentation is called for the the view to be presented, at that time a portrait view is on screen. So, even though the device orientation is landscape, the default return value of preferredInterfaceOrientationForPresentation is portrait. Hence this issue comes up.

Now for solution,
You can do any of the following steps to solve this problem:
Case 1: if you indeed have a preferredInterfaceOrientation for your viewController then just implement the method
in your centerController and return your preferred orientation.

Case 2: If you don't have any preferred orientation (as was the case for me) then just get rid of preferredInterfaceOrientationForPresentation method from IIViewDeckController.m. It is suggested by apple to not use this method if you don't have any preferredInterfaceOrientation.

Case 3: If you don't want to make any change in code of IIViewDeckController, then just implement
method in your centerController and return self.interfaceOrientation from it.

@michaelochs michaelochs added the help label Oct 16, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment