0

Embarcadero C++Builder 10.3.2 企业版

在互联网上搜索,我找不到任何 FMX 代码。基于 Delphi 代码,这应该可以工作,但编译器不喜欢它

if (Application->FormFactor->Orientations == Fmx::Types::TScreenOrientations::Landscape) {
    //Landscape
}

此外,无论 iphone 的方向如何,Application->FormFactor->Orientations 的值都是相同的。{System::SetBase = {Data = {[0] = 11 '\v'}}} 如何确定方向?

4

1 回答 1

1

Orientations属性是 a ,TFormOrientations它是一个System::SetTFormOrientation。您不能Set::operator==将其与单个值进行比较,这就是您收到编译器错误的原因。但是,您可以使用该Set::Contains()方法检查它是否具有给定值,例如:

if (Application->FormFactor->Orientations.Contains(Fmx::Forms::TFormOrientation::Landscape)) {
    //...
}

在任何情况下,该Orientations属性指定允许应用程序的表单采用哪些方向(值 11 将其第 1、第 2 和第 4 位设置为 1,对应于启用的PortraitLandscapeInvertedLandscape方向)。它不报告设备的当前方向。为此,请改用该IFMXScreenService::GetScreenOrientation()方法,例如:

_di_IFMXScreenService ScreenService;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService)) {
    if (ScreenService->GetScreenOrientation() == Fmx::Types::TScreenOrientation::Landscape) {
        //...
    }
}

于 2019-10-31T21:26:38.173 回答