I'm working on application for iOS 5 and I have one controller which needs to be pushed in portrait view. It's quite tricky to push controller in portrait mode from the landscape but finally I figured out how to do that. I show controller by presentModalViewController or by pushViewController and inside the controller I override preferredInterfaceOrientationForPresentation metod.
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
It works fine just it has one problem. Below is the scenario.
I tried to fix it by calling [UIViewController attemptRotationToDeviceOrientation] but it doesn't help.
Thanks for any help in advance.
Your saying that working with IOS 5, but preferredInterfaceOrientationForPresentation() method available from IOS 6 onwards only.
To solve your problem (in ios5) you needs to override the shouldAutorotateToInterfaceOrientation() method as like this...
in targeted view controller (View controller which you needed in portrait mode) as like this....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
UPDATED:
in the current view controller (View controller which you needed in landscape mode) as like this....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
I hope you get a better, working solution I did a nasty thing to get working. My problem it was I needed to support from 4.3 to 6.0. Some pushModal functions has changed radically, become deprecated and so on, also there are changes at rotations.
I wrote a RoatatingViewController and I have added to the root. Than I have added push modals and pushviewconcollers, as desired. When I need to pop, than I do a check: if the desired component on the stack is in desired orientation than is good, no changes. Otherwise: pop the landscape and push the portait instance and copy the landscape data to portait.
It isn't nice, it isn't memory efficient, but is working without crashing with all iOS versions. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With