繁体   English   中英

使用 C++ 检测 iPhone 的方向

[英]Detecting orientation of iPhone using C++

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'}}} 如何确定方向?

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

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

在任何情况下, Orientations属性指定允许应用程序的 Forms 采用的方向(值 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) {
        //...
    }
}

If (Screen->Width > Screen->Height) {
  //code here
} else {
  //code here
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM