Modifying FMX_Platform_iOS.pas to support surface mainWindow and add device orientation support

Posted by on in Blogs
Here are the steps that I use in order to surface a couple of things that some of my custom iOS components and apps need.

These modifications are not supported by anyone. Except maybe me. You apply them entirely at your own risk.

Modify FMX_Platform_iOS.pas on your MAC as below. It's typically located in the /Developer/Embarcadero/fmi directory.

CAUTION: Save a copy of FMX_Platform_iOS.pas FIRST!
CAUTION: Any update of XE2 will delete your changes, so keep this file around if you have to redo the changes.

...

unit FMX_Platform_iOS;

...

interface

...

// TUIViewController and TUIWindow declarations moved from implementation to interface section

type
{ TUIViewController }

TUIViewController = objcclass(UIViewController)
private
public
function shouldAutorotateToInterfaceOrientation(AinterfaceOrientation: UIInterfaceOrientation): Boolean; override;
procedure didReceiveMemoryWarning; override;
procedure didAnimateFirstHalfOfRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation); override;
procedure didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation); override;
end;

{ TUIWindow }

TUIWindow = objcclass(UIWindow)
protected
public
Text: UITextField;
mainView: UIView;
mainController: TUIViewController;
end;

// mainWindow moved from implementation to interface section
// currentOrientation added to give current device orientation
// supportsPortrait etc added. You simply change these in your app code to False if not needed

var
mainWindow: TUIWindow;
currentOrientation : UIInterfaceOrientation;
supportsPortrait : Boolean = True;
supportsPortraitUpsideDown : Boolean = True;
supportsLandscapeRight : Boolean = True;
supportsLandscapeLeft : Boolean = True;

implementation

...

function TUIViewController.shouldAutorotateToInterfaceOrientation(
AinterfaceOrientation: UIInterfaceOrientation): Boolean;
begin
Result := ((AinterfaceOrientation = UIInterfaceOrientationLandscapeRight) and supportsLandscapeRight) or
((AinterfaceOrientation = UIInterfaceOrientationLandscapeLeft) and supportsLandscapeLeft) or
((AinterfaceOrientation = UIInterfaceOrientationPortrait) and supportsPortrait) or
((AinterfaceOrientation = UIInterfaceOrientationPortraitUpsideDown) and supportsPortraitUpsideDown);

if Result then
currentOrientation := AinterfaceOrientation;
end;

...
Enjoy!
Comments are not available for public users. Please login first to view / add comments.