[英]Screen orientation on iOS
Per this question in Delphi an FMX app can be selectively forced into landscape or portrait with code like this:根据 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;
I can't figure out how to translate this code above to C++Builder.我不知道如何将上面的代码翻译成 C++Builder。 I tried the following code based on this post but it gives access violation on both iOS and Android:
我根据这篇文章尝试了以下代码,但它在 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);
}
}
Is this even doable in FMX with C++Builder?这在使用 C++Builder 的 FMX 中是否可行?
This line:这一行:
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
should be this instead:应该是这样的:
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &Intf))
Note the addition of the &
operator in the last parameter.请注意在最后一个参数中添加了
&
运算符。 This is even stated in the documentation :这甚至在文档中都有说明:
Note: Please consider that you need to add & before Intf, as you can see in the code sample above.
注意:请考虑您需要在 Intf 之前添加 &,如您在上面的代码示例中所见。
Also, Intf
really should be declared to match the interface you are requesting, eg:此外,确实应该声明
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.