[FMX]使用 FMX 那些缺失的动画效果

FMX 里的动画做起来简单So easy! TFloatAnimation 不能对一些整数类型的属性做动态效果。

实际上,我们并不需要太沮丧,毕竟天生我材必有用,今天吃饱了明天还饿,这只是因为官方忘了将TIntAnimation注册到面板上而已,我们只需要动态创建它并设置相关属性。

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Ani,
  FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    FloatAnimation1: TFloatAnimation;
    Button1: TButton;
    FloatAnimation2: TFloatAnimation;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    FFormAnimation: TIntAnimation;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
  FFormAnimation.Start;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FFormAnimation := TIntAnimation.Create(Self);
  FFormAnimation.Parent := Self;
  FFormAnimation.StartValue := 0;
  FFormAnimation.StopValue := (Screen.Width - Width) div 2;
  FFormAnimation.Interpolation := TInterpolationType.Bounce;
  FFormAnimation.Duration:=2;
  FFormAnimation.PropertyName:='Left';
  Top := (Screen.Height - Height) div 2;
end;

end.

好了,现在就一切OK。

分享到: