Basis bildet eine VertScrollbox mit TAlignLayout.alClient, die als Container für alle Controls dient.
Im Form-Event FormFocusChanged:
Delphi-Quellcode:
procedure TfrmMain.FormFocusChanged(Sender: TObject);
begin
{$IFDEF IOS}
UpdateKBBounds;
{$ENDIF IOS}
end;
UpdateKBounds:
Delphi-Quellcode:
{$IFDEF IOS}
procedure TfrmMain.UpdateKBBounds;
var
LFocused : TControl;
LFocusRect: TRectF;
begin
FNeedOffset := False;
if Assigned(Focused) then
begin
LFocused := TControl(Focused.GetObject);
LFocusRect := LFocused.AbsoluteRect;
LFocusRect.Offset(VertScrollBox1.ViewportPosition);
if (LFocusRect.IntersectsWith(TRectF.Create(FKBBounds))) and
(LFocusRect.Bottom > FKBBounds.Top) then
begin
FNeedOffset := True;
laMain.Align := TAlignLayout.alHorizontal;
VertScrollBox1.RealignContent;
Application.ProcessMessages;
VertScrollBox1.ViewportPosition :=
PointF(VertScrollBox1.ViewportPosition.X,
LFocusRect.Bottom - FKBBounds.Top-15);
end;
end;
if not FNeedOffset then
RestorePosition;
end;
{$ENDIF ENDIF}
RestorePosition:
Delphi-Quellcode:
{$IFDEF IOS}
procedure TfrmMain.RestorePosition;
begin
VertScrollBox1.ViewportPosition := PointF(VertScrollBox1.ViewportPosition.X, 0);
laMain.Align := TAlignLayout.alClient;
VertScrollBox1.RealignContent;
end;
{$ENDIF ENDIF}
Delphi-Quellcode:
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
{$IFDEF IOS}
FKBBounds: TRectF;
FNeedOffset: Boolean;
procedure CalcContentBoundsProc(Sender: TObject;
var ContentBounds: TRectF);
procedure RestorePosition;
procedure UpdateKBBounds;
function SharedApplication:UIApplication;
{$ENDIF}
end;
FormCreate:
Delphi-Quellcode:
procedure TfrmMain.FormCreate(Sender: TObject);
begin
{$IF Defined(IOS)}
VertScrollBox1.OnCalcContentBounds := CalcContentBoundsProc;
{$ENDIF}
end;
und CalcContentBoundsProc:
Delphi-Quellcode:
{$IFDEF IOS}
procedure TfrmMain.CalcContentBoundsProc(Sender: TObject;
var ContentBounds: TRectF);
begin
if FNeedOffset and (FKBBounds.Top > 0) then
begin
ContentBounds.Bottom := Max(ContentBounds.Bottom,
2 * ClientHeight - FKBBounds.Top);
end;
end;
{$ENDIF}
Quelle ist mir leider nicht mehr bekannt.