basically all I want to achieve is when a user is in a certain part of the App to change the screen rotation as needed, I have this working for Andriod and I can not see why it shouldn’t work for 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;
Taken from here : How to prevent screen rotation with android development in delphi xe5 Firemonkey
The ScreenService.SetScreenOrientation is executed and does not raise a exception but the orientation is not changed, I have also set Enable custom orientation in Project>Options>Application>Orientation but this also didn’t have any effect.
What is strange to me is that if it was not supported then shouldn’t this
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
Return false? and not even enter the begin
I added a test button to check the screen orientation after I set it to landscape only with
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
then
begin
case ScreenService.GetScreenOrientation of
TScreenOrientation.Portrait: ShowMessage(‘Portriat’);
TScreenOrientation.Landscape: ShowMessage(‘landscape’);
TScreenOrientation.InvertedPortrait: ShowMessage(‘Inverted-Portriat’);
TScreenOrientation.InvertedLandscape: ShowMessage(‘Inverted-Landscape’);
else ShowMessage(‘not set’);
end;
end;
And if it was in Portrait after setting it to Landscape it still says Portrait
Update 1 : I have also tried changing
OrientSet := [TScreenOrientation.soLandscape] // <- Deprecated
to
OrientSet := [TScreenOrientation.Landscape]
but the behaviour is still the same