简体   繁体   English

使用 C++ 检测 iPhone 的方向

[英]Detecting orientation of iPhone using C++

Embarcadero C++Builder 10.3.2 Enterprise Embarcadero C++Builder 10.3.2 企业版

Searching the internet, I could not find any FMX code for this.在互联网上搜索,我找不到任何 FMX 代码。 Based on Delphi code, this should have worked but the compiler does not like it基于 Delphi 代码,这应该可以工作,但编译器不喜欢它

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

Also, the value of Application->FormFactor->Orientations is the same whatever the orientation of the iphone.此外,无论 iphone 的方向如何,Application->FormFactor->Orientations 的值都是相同的。 {System::SetBase = {Data = {[0] = 11 '\v'}}} How does one determine the orientation? {System::SetBase = {Data = {[0] = 11 '\v'}}} 如何确定方向?

The Orientations property is a TFormOrientations , which is a System::Set of TFormOrientation values. Orientations属性是一个TFormOrientations ,它是一个System::Set TFormOrientation值。 You can't use Set::operator== to compare it to a single value, which is why you are getting a compiler error.您不能使用Set::operator==将其与单个值进行比较,这就是您收到编译器错误的原因。 However, you can use theSet::Contains() method to check if it has a given value, eg:但是,您可以使用Set::Contains()方法来检查它是否具有给定值,例如:

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

In any case, the Orientations property specifies which orientation(s) the application's Forms are allowed to take (a value of 11 has its 1st, 2nd, and 4th bits set to 1, which correspond to the Portrait , Landscape , and InvertedLandscape orientations being enabled).在任何情况下, Orientations属性指定允许应用程序的 Forms 采用的方向(值 11 将其第 1、2 和 4 位设置为 1,对应于PortraitLandscapeInvertedLandscape方向启用)。 It does not report what the device's current orientation is.它不报告设备的当前方向。 For that, use the IFMXScreenService::GetScreenOrientation() method instead, eg:为此,请改用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