I'd have thought there would be an OnRotate
event in XE4 but it appears that OnResize
is used. Got that.
However, I need to determine which orientation the device is. I'm sure it's simple but Google can't help!
To detect the current orientation of the device you can use the statusBarOrientation
method which is part of the UIApplication
class.
Try this sample
uses
iOSapi.UIKit;
function SharedApplication:UIApplication;
begin
Result:=TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
end;
procedure TForm23.Button1Click(Sender: TObject);
var
LOrientation: Cardinal;
begin
LOrientation := SharedApplication.statusBarOrientation;
if (LOrientation = UIDeviceOrientationLandscapeLeft) or (LOrientation = UIDeviceOrientationLandscapeRight) then
ShowMessage('Landscape')
else
if (LOrientation = UIInterfaceOrientationPortrait) then
ShowMessage('Portrait');
end;
Seems that checking the hieght and width is the way. If h > w then potrait, else landscape. Surprised there isn't something built in though.
You can use my function on OnResize event of the main form.
function TERMainForm.GetOrientation: TScreenOrientation; var
OrientationS: IFMXScreenService; begin
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(OrientationS)) then
begin Result := OrientationS.GetScreenOrientation;
end
else raise Exception.Create('Orientation not supported'); end;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.