Das Beispiel ist relativ kompliziert umgesetzt und funktionert ja nur hochkant.
Ich habe das für meine Bedürfnisse angepasst. Ich bin dabei davon ausgegangen, dass das Keyboard immer von unten eingeblendet wird.
Hier mein Quellcode:
Code:
constructor TEForm.Create(AOwner: TComponent);
begin
OnVirtualKeyboardShown := FormVirtualKeyboardShown;
OnVirtualKeyboardHidden := FormVirtualKeyboardHidden;
OnFocusChanged := FormFocusChanged;
MainVertScrollBox.OnCalcContentBounds := CalcContentBoundsProc;
end;
procedure TEForm.CalcContentBoundsProc(Sender: TObject;
var ContentBounds: TRectF);
begin
if KeyBoardVerdecktFeld and (KeyBoardPositionY > 0) then
ContentBounds.Bottom := Max(ContentBounds.Bottom,
2 * ClientHeight - KeyBoardPositionY);
end;
procedure TEForm.FormVirtualKeyboardHidden(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
begin
KeyBoardPositionY:=0;
KeyBoardVerdecktFeld := False;
KeyBoardRestorePosition;
end;
procedure TEForm.FormVirtualKeyboardShown(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
begin
KeyBoardPositionY := Self.ClientHeight - Bounds.Height;
KeyBoardErmittlePosition;
end;
procedure TEForm.KeyBoardRestorePosition();
begin
MainVertScrollBox.ViewportPosition := PointF(MainVertScrollBox.ViewportPosition.X, 0);
MainLayout.Align := TAlignLayout.alClient;
MainVertScrollBox.RealignContent;
KeyBoardPositionY := 0;
end;
procedure TEForm.KeyBoardErmittlePosition;
var
LFocused : TControl;
LFocusRect: TRectF;
begin
KeyBoardVerdecktFeld := False;
if Assigned(Focused) then
begin
LFocused := TControl(Focused.GetObject);
LFocusRect := LFocused.AbsoluteRect;
LFocusRect.Offset(MainVertScrollBox.ViewportPosition);
if (KeyBoardPositionY<>0) and (LFocusRect.Bottom>KeyBoardPositionY) then begin;
KeyBoardVerdecktFeld := True;
MainLayout.Align := TAlignLayout.alHorizontal;
MainVertScrollBox.RealignContent;
Application.ProcessMessages;
MainVertScrollBox.ViewportPosition :=
PointF(MainVertScrollBox.ViewportPosition.X,
LFocusRect.Bottom - KeyBoardPositionY);
end;
end;
if not KeyBoardVerdecktFeld then
KeyBoardRestorePosition;
end;
Das funzt bei mir in allen Ausrichtungen.