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::Set
的 TFormOrientation
值。你不能使用 Set::operator==
将其与单个值进行比较,这就是您收到编译器错误的原因。但是,您可以使用 Set::Contains()
检查它是否具有给定值的方法,例如:
if (Application->FormFactor->Orientations.Contains(Fmx::Forms::TFormOrientation::Landscape)) {
//...
}
在任何情况下,Orientations
属性指定应用程序的表单允许采用的方向(值 11 有其第 1、第 2 和第 4位设置为 1,对应于启用的Portrait
、Landscape
和InvertedLandscape
方向)。它不报告设备的当前方向。为此,请使用 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/