Jump to content

Stewag

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. procedure TfMain.IOSTurn(Portrait: boolean); // Source: https://en.delphipraxis.net/topic/1796-firemonkey-change-ios-screen-rotation-at-runtime/ var LID: Pointer; begin if Portrait then begin Application.FormFactor.Orientations := [TScreenOrientation.Portrait, TScreenOrientation.InvertedPortrait]; if not TOSVersion.Check(16) then // iOS lower than 16 begin showmessage('Please turn phone back to portrait'); TurnIOStoPortrait := False; // turn off message to prevent multiple display end; end else begin Application.FormFactor.Orientations := [TScreenOrientation.Landscape, TScreenOrientation.InvertedLandscape]; end; if TOSVersion.Check(16) then // iOS Version 16 and up begin LID := NSObjectToID(TiOSHelper.sharedApplication.keyWindow.rootViewController); TUIViewControllerEx.Wrap(LID).setNeedsUpdateOfSupportedInterfaceOrientations; end else // iOS 13: no automatic rotation. Not tested for iOS<13 begin TUIViewController.OCClass.attemptRotationToDeviceOrientation; if TabControl1.ActiveTab.Name = 'XXX' then // limit message to specific tab showmessage('Please turn phone to landscape'); end end; Dave's code works magnificently - thank you Dave! Here is an alternative procedure to Dave's Button1Click() that works both ways and includes messages to rotate the phone manually. This is necessary for iOS lower than 16, where the content but not the display is rotated by the code. In IOS 16 and up, rotation is done smoothly automatically. I could only test iOS 13 though, maybe someone can extend the code to iOS < 13? Steffen
×