根据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 中是否可行?