0

[I know this has been done to death, and I'd ask follow up questions on an existing question were it not for not having enough stackoverflow points to make one:(]

I'm after an App Store valid way of forcing an existing UI to re-orientate without having to destroy the main ViewController or View. We work in fullscreen mode, so I'm assuming I can't use any of the toolbar approaches normally quoted. Finally I'm only interested in iOS5.

For iOS6 I have a solution based on the answers in How to change the device orientation programmatically in iOS 6. I used the solution which includes ForcePortrait, with the variation that I changed it so I can supply the required orientation as a parameter.

For iOS5 I have experimented with the suggestion of:

[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];

from How to set device (UI) orientation programmatically?. This works well but I'm worried that it would be rejected by App Store (complete no no for us).

Has anyone used this on something that has App Store approval and/or got a better suggestion?

Community
  • 1
  • 1
johnfo
  • 1,676
  • 2
  • 17
  • 28
  • FTR I tried my iOS6 solution on iOS5 with the variation that I set the status bar orientation first (status bar is hidden, but tried anyway). This is I believe the basis of some of the iOS5 suggestions - change status bar and then create a new view - but it did not work for me. – johnfo Aug 07 '13 at 11:47
  • You can use this http://stackoverflow.com/questions/4330979/how-to-set-device-ui-orientation-programmatically Apple allow this. – sundar Aug 07 '13 at 12:19
  • Please explain what you're trying to do. Generally, the user initiates an orientation change. – Marcus Adams Aug 07 '13 at 13:17
  • I think that is Apple's view, but reality is there are scenarios where the views are designed as portrait or landscape only. Generally ones not made up of standard UI controls/features that when rotated you merely rearrange etc. The specific case relates to a collection of games, but I'm sure the issue is more general than than that. – johnfo Aug 08 '13 at 05:00

2 Answers2

0

Check this out: Force Rotate UIViewController.

Maybe it will work. This is however very hackish.

Community
  • 1
  • 1
chrs
  • 5,906
  • 10
  • 43
  • 74
0

[Found a solution, at any rate. Not sure if it the best.]

Got the temporary UIViewController approach to work by adding shouldAutorotateToInterfaceOrientation. The meaning of this is overloaded by iOS5 to discover not only should it autoRotate but also should it start in a particular orientation to start with - I guess that is why it is replaced by several methods at iOS6.. Thus we return true in orientations that are OK.

Perhaps should have realised that before.

Not quite as neat as the setOrientation hack. Key glitch we've noticed is that when you then rotate the device around to the proper orientation you still get a rotation animation. This does not occur on iOS6. Oh well, you win some, you lose some.

johnfo
  • 1,676
  • 2
  • 17
  • 28