簡體   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