在Delphi中检测iPad的方向

Mar*_*ore 1 delphi ios delphi-xe4

我原以为OnRotate在XE4中会有一个事件,但它似乎OnResize被使用了.了解.

但是,我需要确定设备的方向.我确信它很简单,但谷歌无法帮助!

RRU*_*RUZ 6

要检测设备的当前方向,您可以使用statusBarOrientation属于UIApplication该类的方法.

试试这个样本

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;
Run Code Online (Sandbox Code Playgroud)