Einzelnen Beitrag anzeigen

Rollo62

Registriert seit: 15. Mär 2007
3.908 Beiträge
 
Delphi 12 Athens
 
#4

AW: [FMX] Ändern der FormOrientation per Code

  Alt 1. Jun 2017, 21:24
Was passiert denn wenn du nur eine Möglichkeit hier setzt ?

Application.FormFactor.Orientations := [TFormOrientation.Landscape]; oder
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

Geändert von Rollo62 ( 1. Jun 2017 um 21:28 Uhr)
  Mit Zitat antworten Zitat