iOS上的屏幕方向

问题描述 投票:0回答:1

在Delphi中,每个this question都可以使用以下代码将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。我尝试了以下基于on this post的代码,但它在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中实现吗?

firemonkey c++builder c++builder-10.3-rio
1个回答
1
投票

此行:

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

应该是这个:

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

注意最后一个参数中添加了&运算符。甚至在documentation中也有说明:

注意:请注意,您需要在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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.