Jump to content

[Firemonkey ]Change iOS screen rotation at runtime

Recommended Posts


I need to rotate the screen at runtime when I open a form.
Until the release of IOS 13 this code worked perfectly:


procedure ChangeOrientation(toOrientation: UIInterfaceOrientation; possibleOrientations: TScreenOrientations);
  win : UIWindow;
  App : UIApplication;
  viewController : UIViewController;
  oucon: UIViewController;

  Application.FormFactor.Orientations := []; //Change supported orientations
  App := TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
  win := TUIWindow.Wrap(App.windows.objectAtIndex(0)); //The first Windows is always the main Window


  {After you have changed your statusbar orientation set the
  Supported orientation/orientations to whatever you need}
  Application.FormFactor.Orientations := possibleOrientations;

  viewController := TUIViewController.Wrap(TUIViewController.alloc.init);//dummy ViewController
  oucon := TUIViewController.Wrap(TUIViewController.alloc.init);
  {Now we are creating a new Viewcontroller now when it is created
   it will have to check what is the supported orientations}
  oucon := win.rootViewController;//we store all our current content to the new ViewController
  Win.makeKeyAndVisible;// We display the Dummy viewcontroller


  {And now we Display our original Content in a new Viewcontroller
   with our new Supported orientations}

However, since the release of IOS 13 the screen locks on the set orientation but does not rotate. So if I set Landscape orientation the screen remains in Portrait orientation until I physically turn the phone around, at which point it rightly remains locked on that orientation.
This is a real disaster because then, until the phone is turned, all the controls ( finger position, object position,..) are wrong.


Share this post

Link to post

Looking for a solution too, since I used same code as yours.
Seems that SetStatusBar was deprecated, and now in iOS 13 its probably gone.




Edited by Rollo62

Share this post

Link to post

Yes, I know that the SetStatusBar function is obsolete and now there is no other function to do it.
I found a solution, to open the module that I would like to show only in Landscape, I show a message to the user to inform him that he must rotate the phone to open it.
Then, when the user rotates the phone, the "onResize" event is activated. In this event the orientation is set only to Landscape and then the form is opened.

Share this post

Link to post

Ok, that is a workaround.
But I hope that there is a better way ... Apple strikes back on iOS13 again ... I'm just still fixing other similar issues.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now