c++ - 使用 C++ 检测 iPhone 的方向

标签 c++ firemonkey c++builder-10.3-rio

Embarcadero C++Builder 10.3.2 企业版

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

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

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

最佳答案

Orientations 属性是一个 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) {
        //...
    }
}

关于c++ - 使用 C++ 检测 iPhone 的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58599687/

相关文章:

ios - 带有 Indy 或第三方 Internet 组件的 iOS 上的 Delphi XE2

c++ - 使用 scanf 过滤掉负数

c++ - boost::program_options 位置选项

delphi - Delphi 11.1 FMX 关闭时 TGPUObjectsPool 内存泄漏

delphi - FMX : Flatten Multiple Images

firemonkey - 如何为 FMX 控件添加缺失的边框?

firemonkey - Info.plist 中的 UIFileSharingEnabled 键

c++ - 使用宏为 C++ 类方法生成空代码

c++ - 为什么 C++ 不捕获这个异常?