[英]Firemonkey Listview & mobile screen orientation in Delphi 11
[英]Screen orientation on iOS
根据 Delphi 中的这个问题,可以使用如下代码选择性地将 FMX 应用程序强制为横向或纵向:
procedure TForm1.Chart1Click(Sender: TObject);
begin
if Application.FormFactor.Orientations = [TScreenOrientation.Landscape] then
Application.FormFactor.Orientations := [TScreenOrientation.Portrait]
else
Application.FormFactor.Orientations := [TScreenOrientation.Landscape];
end;
end;
我不知道如何将上面的代码翻译成 C++Builder。 我根据这篇文章尝试了以下代码,但它在 iOS 和 Android 上都出现了访问冲突:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
_di_IInterface Intf;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
{
_di_IFMXScreenService ScreenService = Intf;
TScreenOrientations Orientation;
Orientation << TScreenOrientation::Landscape;
ScreenService->SetScreenOrientation(Orientation);
}
}
这在使用 C++Builder 的 FMX 中是否可行?
这一行:
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
应该是这样的:
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &Intf))
请注意在最后一个参数中添加了&
运算符。 这甚至在文档中都有说明:
注意:请考虑您需要在 Intf 之前添加 &,如您在上面的代码示例中所见。
此外,确实应该声明Intf
以匹配您请求的接口,例如:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
_di_IFMXScreenService ScreenService;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService))
{
TScreenOrientations Orientation;
Orientation << TScreenOrientation::Landscape;
ScreenService->SetScreenOrientation(Orientation);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.