Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   iOS [FMX] Ändern der FormOrientation per Code (https://www.delphipraxis.net/192894-%5Bfmx%5D-aendern-der-formorientation-per-code.html)

Darlo 31. Mai 2017 08:03

[FMX] Ändern der FormOrientation per Code
 
Hallo zusammen,

ich baue gerade eine App in der nur ein Form im Querformat angezeigt werden soll.
In der Projektdatei steht
Delphi-Quellcode:
  Application.FormFactor.Orientations := [TFormOrientation.Portrait, TFormOrientation.InvertedPortrait];
Soweit so gut, Querformat ist geblockt. Jetzt zeige ich eine Form die im Querformat erscheinen soll an:

Delphi-Quellcode:
 Application.FormFactor.Orientations := [TFormOrientation.Landscape, TFormOrientation.InvertedLandscape];
 frmQuer.Show;
Im frmQuer.OnClose:
Delphi-Quellcode:
 Application.FormFactor.Orientations := [TFormOrientation.Portrait, TFormOrientation.InvertedPortrait];
Wie kann ich dem Gerät denn mitteilen dass es die neue Orientierung übernehmen soll, sprich sofort zeichnen. Aktuell muss das Gerät gedreht werden, dann wird die neue Orientierung angenommen und der Rest geblockt.

Gruss

Rollo62 1. Jun 2017 01:15

AW: [FMX] Ändern der FormOrientation per Code
 
Hallo Darlo,

versuch mal das
Delphi-Quellcode:
// Sets the possible Screen orientations (Portrait, Landscape, InvertedPortrait, InvertedLandscape);
procedure Form_Orientation_Set2(const orientSet : TScreenOrientations );
var
  ScreenService: IFMXScreenService;

begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService)) then
  begin
    ScreenService.SetScreenOrientation(orientSet);
  end;
end;
Bin mir nicht mehr sicher obs auch eine Drehung des Gerätes erwartet.

Rollo

Darlo 1. Jun 2017 12:17

AW: [FMX] Ändern der FormOrientation per Code
 
Hallo Rollo,

danke für Deine Antwort. Leider wird hierbei die View auch nicht automatisch gedreht. Ich habe, zumindest für iOS, hier eine Lösung gefunden:

https://stackoverflow.com/questions/...ion-at-runtime

Gruss

Rollo62 1. Jun 2017 21:24

AW: [FMX] Ändern der FormOrientation per Code
 
Was passiert denn wenn du nur eine Möglichkeit hier setzt ?

Delphi-Quellcode:
Application.FormFactor.Orientations := [TFormOrientation.Landscape];
oder
Delphi-Quellcode:
Application.FormFactor.Orientations := [TFormOrientation.Portrait];

Wenn es z.b. Portait ist und du setzt Landscape in die möglichen Orientazions, erzwingt man damit nicht die Drehung
auch ohne dass das Gerät sich dreht ?

Das gibt es in den D.P.F. Controls:
Delphi-Quellcode:

// ------------------------------------------------------------------------------
function ScreenForceRotate( IfOrientationNotIn: TScreenOrientation ): boolean;
const
  ConvOri: array [TScreenOrientation] of NativeUInt = ( UIDeviceOrientationPortrait, UIDeviceOrientationLandscapeRight, UIDeviceOrientationPortraitUpsideDown, UIDeviceOrientationLandscapeLeft );
var
  w: UIWindow;
  v: UIView;
  // ScreenService : IFMXScreenService;
  MainRroot  : UIViewController;
  Orientations: TFormOrientations;
  // CurOrientation: TScreenOrientation;
begin
  Orientations := Application.FormFactor.Orientations;
  try
    (*
      if TPlatformServices.Current.SupportsPlatformService( IFMXScreenService, IInterface( ScreenService ) ) then
      CurOrientation := ScreenService.GetScreenOrientation
      else
      CurOrientation := TScreenOrientation.soPortrait;

      Result          := CurOrientation <> IfOrientationNotIn;
    *)
    Result := true; // CurOrientation <> IfOrientationNotIn;

    if Result then
    begin

      MainRroot := GetSharedApplication.keyWindow.rootViewController;

      Application.FormFactor.Orientations := [TScreenOrientation.Portrait, TScreenOrientation.Landscape, TScreenOrientation.InvertedPortrait, TScreenOrientation.InvertedLandscape];
      GetSharedApplication.keyWindow.setRootViewController( nil );
      // application.ProcessMessages;

      GetSharedApplication.setStatusBarOrientation( ConvOri[IfOrientationNotIn] );
      TUIDevice.Wrap( TUIDevice.OCClass.currentDevice ).performSelector( sel_getUid( 'setOrientation:' ), ( TNSNumber.Wrap( TNSNumber.OCClass.numberWithUnsignedInt( ConvOri[IfOrientationNotIn] ) ) as ILocalObject ).GetObjectID, 0 );

      w := GetSharedApplication.keyWindow;
      if w.subviews.count > 0 then
      begin
        v := TUIView.Wrap( w.subviews.objectAtIndex( 0 ) );
        v.removeFromSuperview;
        w.insertSubview( v, 0 );
      end;
      GetSharedApplication.keyWindow.setRootViewController( MainRroot );
      GetSharedApplication.keyWindow.rootViewController.didRotateFromInterfaceOrientation( ConvOri[IfOrientationNotIn] );

    end;
  finally
    Application.FormFactor.Orientations := Orientations;
  end;
end;
Rollo

Darlo 1. Jun 2017 21:26

AW: [FMX] Ändern der FormOrientation per Code
 
Leider unter iOS nicht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:43 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz