【Delphi】 Android&IOS 实现frame滑动页面。
先看效果图。
思路比较简单,利用TFloatAnimation实现frame动画。
即将进入的界面移入的同时,当前界面向左滑动。
procedure TAniFrameBase.showPage(obj: TAniFrameBase = nil;Inverse: Boolean = False);
begin
if aniTag then Exit; //正在显示动画则退出
aniTag := True;
if Inverse then //这个是当前frame向左滑出
begin
fltnmtn_scroll.StartValue := 0;
fltnmtn_scroll.StopValue := -Width / 2;
end
else begin
Visible := True;
BringToFront;
fltnmtn_scroll.StartValue := Width;
fltnmtn_scroll.StopValue := 0;
prePage := obj;
if obj <> nil then //当前界面向左滑出
begin
prePage.Visible := True;
prePage.showPage(nil,True);
end;
end;
fltnmtn_scroll.Start; //显示界面进入
end;
回退时,当前界面向右滑出,展示界面从左滑入。
procedure TAniFrameBase.closePage(Inverse: Boolean= False);
begin
if aniTag then Exit;
aniTag := True;
if Inverse then //关闭时
begin
fltnmtn_scroll.StartValue := -Width / 2;
fltnmtn_scroll.StopValue := 0;
end
else begin
Visible := True;
fltnmtn_scroll.StartValue := 0;
fltnmtn_scroll.StopValue := Width;
if prePage <> nil then
begin
prePage.Visible := True;
prePage.closepage(True);
end;
end;
fltnmtn_scroll.Start;
end;
完整代码例子:
https://download.csdn.net/download/liverry/12698805
注意:新建的TFrame,选择继承自TAniFrameBase就行了。