基本上我想要实现的是当用户在应用程序的某个部分根据需要更改屏幕旋转时,我有这个适用于 Andriod,我不明白为什么它不应该适用于 iOS
procedure TForm1.Button1Click(Sender: TObject);
var
ScreenService: IFMXScreenService;
OrientSet: TScreenOrientations;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
then
begin
OrientSet := [TScreenOrientation.soLandscape];//<- Break point set here and line is executed
ScreenService.SetScreenOrientation(OrientSet);
end;
end;
取自这里:如何在delphi xe5 Firemonkey中使用android开发防止屏幕旋转
ScreenService.SetScreenOrientation 被执行并且不会引发异常但方向没有改变,我还在 Project>Options>Application>Orientation 中设置了Enable custom orientation但这也没有任何效果。
对我来说奇怪的是,如果不支持它,那么不应该这样吗
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
返回假?甚至没有进入开始
在我将其设置为横向后,我添加了一个测试按钮来检查屏幕方向
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
then
begin
case ScreenService.GetScreenOrientation of
TScreenOrientation.Portrait: ShowMessage('Portrait');
TScreenOrientation.Landscape: ShowMessage('landscape');
TScreenOrientation.InvertedPortrait: ShowMessage('Inverted-Portrait');
TScreenOrientation.InvertedLandscape: ShowMessage('Inverted-Landscape');
else ShowMessage('not set');
end;
end;
如果它在设置为横向后是纵向的,它仍然会显示纵向
更新1:我也尝试过改变
OrientSet := [TScreenOrientation.soLandscape] // <- Deprecated
到
OrientSet := [TScreenOrientation.Landscape]
但行为仍然相同