AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

[FMX] Ändern der FormOrientation per Code

Offene Frage von "Rollo62"
Ein Thema von Darlo · begonnen am 31. Mai 2017 · letzter Beitrag vom 1. Jun 2017
Antwort Antwort
Darlo

Registriert seit: 28. Jul 2008
Ort: München
1.196 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#1

[FMX] Ändern der FormOrientation per Code

  Alt 31. Mai 2017, 09:03
Hallo zusammen,

ich baue gerade eine App in der nur ein Form im Querformat angezeigt werden soll.
In der Projektdatei steht
  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:
 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
Philip
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.882 Beiträge
 
Delphi 12 Athens
 
#2

AW: [FMX] Ändern der FormOrientation per Code

  Alt 1. Jun 2017, 02:15
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
  Mit Zitat antworten Zitat
Darlo

Registriert seit: 28. Jul 2008
Ort: München
1.196 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#3

AW: [FMX] Ändern der FormOrientation per Code

  Alt 1. Jun 2017, 13:17
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
Philip
  Mit Zitat antworten Zitat
Rollo62

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

AW: [FMX] Ändern der FormOrientation per Code

  Alt 1. Jun 2017, 22: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 22:28 Uhr)
  Mit Zitat antworten Zitat
Darlo

Registriert seit: 28. Jul 2008
Ort: München
1.196 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#5

AW: [FMX] Ändern der FormOrientation per Code

  Alt 1. Jun 2017, 22:26
Leider unter iOS nicht.
Philip
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:21 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