簡體   English   中英

iOS 上的屏幕方向

[英]Screen orientation on iOS

根據 Delphi 中的這個問題,可以使用如下代碼選擇性地將 FMX 應用程序強制為橫向或縱向:

procedure TForm1.Chart1Click(Sender: TObject);
begin
  if Application.FormFactor.Orientations = [TScreenOrientation.Landscape] then
     Application.FormFactor.Orientations := [TScreenOrientation.Portrait]
  else
     Application.FormFactor.Orientations := [TScreenOrientation.Landscape];
  end;
end;

我不知道如何將上面的代碼翻譯成 C++Builder。 我根據這篇文章嘗試了以下代碼,但它在 iOS 和 Android 上都出現了訪問沖突:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 _di_IInterface Intf;
 if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
 {
 _di_IFMXScreenService ScreenService = Intf;
 TScreenOrientations Orientation;
 Orientation << TScreenOrientation::Landscape;
 ScreenService->SetScreenOrientation(Orientation);
 }
}

這在使用 C++Builder 的 FMX 中是否可行?

這一行:

if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))

應該是這樣的:

if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &Intf))

請注意在最后一個參數中添加了&運算符。 這甚至在文檔中都有說明:

注意:請考慮您需要在 Intf 之前添加 &,如您在上面的代碼示例中所見。

此外,確實應該聲明Intf以匹配您請求的接口,例如:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    _di_IFMXScreenService ScreenService;
    if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService))
    {
        TScreenOrientations Orientation;
        Orientation << TScreenOrientation::Landscape;
        ScreenService->SetScreenOrientation(Orientation);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM