繁体   English   中英

在Delphi中检测iPad方向

[英]Detecting iPad orientation in Delphi

我以为XE4中会有一个OnRotate事件,但是似乎使用了OnResize 知道了。

但是,我需要确定设备的方向。 我敢肯定这很简单,但Google帮不上忙!

要检测设备的当前方向,可以使用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;

似乎是检查高度和宽度的方法。 如果h> w,则表示potrait,否则为风景。 惊讶的是虽然没有内置任何东西。

您可以在主窗体的OnResize事件上使用我的函数。

函数TERMainForm.GetOrientation:TScreenOrientation; 变种
方向:IFMXScreenService; 开始
如果TPlatformServices.Current.SupportsPlatformService(IFMXScreenService,IInterface(OrientationS)),则
begin结果:= OrientationS.GetScreenOrientation;
结束
否则引发Exception.Create('不支持方向'); 结束;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM