Reputation: 363
I have an iPad application that opens up in portrait mode but when I switch to another view I need to force the orientation to landscape so that the user realises they need to physically move the screen orientation to landscape, and then when they leave this view I need to force the orientation back to portrait.
I can see the ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) which if believe correctly just restricts the orientations that are possible for the view but setting this to one orientation (e.g. UIInterfaceOrientation.LandscapeRight) doesn't force the orientation to change.
I've seen some other suggestions about forcing the View to rotate using this.View.Transform.Rotate(...) but doesn't seem to work for me.
Just wondering if anyone had any suggestions or be able to point me in the right direction?
Thanks
Upvotes: 3
Views: 938
Reputation: 66882
Are your views all displayed within a single uinavigationcontroller?
If they are, then I'm afraid that the answer is that you cannot achieve what you are looking to - see a full explanation, including links to the Apple developer docs on: How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?
If you do want to achieve the effect you are looking for the, then maybe switch to using some other "parent" for all your child views - e.g. displaying them modally?
Upvotes: 1
Reputation: 4133
First, set ShouldAutorotateToInterfaceOrientation
to support landscape orientation only.
Then use this hack to force orientation change:
var c = new UIViewController ();
PresentModalViewController (c, false);
DismissModalViewControllerAnimated (false);
Upvotes: 1