我原以为XE4会有OnRotate
个事件,但似乎使用了OnResize
。得到了。
但是,我需要确定设备的方向。我确信这很简单,但谷歌无法帮助!
答案 0 :(得分:6)
要检测设备的当前方向,您可以使用属于UIApplication
类的statusBarOrientation
方法。
试试这个样本
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;
答案 1 :(得分:1)
似乎检查高度和宽度是这样的。如果h>那么肖像,否则风景。很惊讶没有内置的东西。
答案 2 :(得分:0)
您可以在主窗体的OnResize事件中使用我的函数。
function TERMainForm.GetOrientation:TScreenOrientation; VAR
OrientationS:IFMXScreenService; 开始
如果 TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(OrientationS))然后
开始 结果:= OrientationS.GetScreenOrientation;
结束
其他 提升Exception.Create('Orientation not supported'); 端;