我曾尝试在mousemove事件期间使用TAnimator。 我想在mousemove事件期间使用TAnimator更改组件的大小。 但它没有动画。它只是改变了尺寸。 如何在mousemove事件期间制作动画?
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.StdCtrls,
FMX.Ani;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
private
IsMouseDown: Boolean;
PtX, PtY: Single;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
IsMouseDown := True;
PtX := X;
PtY := Y;
end;
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
var
Anime: TAnimator;
begin
if IsMouseDown then
begin
Button1.Position.X := Button1.Position.X + X - PtX;
Button1.Position.Y := Button1.Position.Y + Y - PtY;
Anime := TAnimator.Create;
try
Anime.AnimateFloat(Button2, 'Width', 400, 1);
finally
Anime.Free;
end;
end;
end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
IsMouseDown := False;
end;
end.
答案 0 :(得分:0)
尝试更像这样的东西:
var
Anim: TFloatAnimation = nil;
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
if Button <> TMouseButton.mbLeft then Exit;
IsMouseDown := True;
PtX := X;
PtY := Y;
end;
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
begin
if not IsMouseDown then Exit;
Button1.Position.X := Button1.Position.X + X - PtX;
Button1.Position.Y := Button1.Position.Y + Y - PtY;
// FYI, you can configure this at design-time as well...
if Anim = nil then
begin
Anim := TFloatAnimator.Create(Button2);
Anim.Parent := Button2;
Anim.PropertyName := 'Width';
Anim.Duration := 1;
Anim.StopValue := 400;
Anim.StartFromCurrent := True;
end;
if (not Anim.Running) and (Button2.Width <> 400) then
Anim.Start;
end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
if Button <> TMouseButton.mbLeft then Exit;
IsMouseDown := False;
if Anim <> nil then
Anim.Stop;
end;
有关详细信息,请参阅以下内容:
Using FireMonkey Animation Effects
Create Floating Animation With TAnimateFloat In Delphi Firemonkey