我试着在安卓系统上用德尔福火猴(柏林)在TButton程序中制作一个简单的TImage从一个度数旋转到另一个度数的动画,如下所示:
procedure TForm1.Button1Click(Sender: TObject);
begin
while Image1.RotationAngle < 360 do begin
Image1.RotationAngle := Image1.RotationAngle+1;
Image1.Repaint;
Sleep(1);
end;
end;我尝试过使用Image1.Repaint和不使用Image1.Repaint,但动画根本不起作用,但当使用TTimer时,它工作得很好。有谁知道怎么解决这个问题吗?
发布于 2017-03-31 22:31:09
将FMX.Ani添加到uses子句中,并在button onlick事件中使用TAnimator:
procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.RotationAngle:=0;
TAnimator.AnimateFloat(Image1,'RotationAngle',360,1,TAnimationType.InOut, TInterpolationType.Exponential );
end;有关参数的详细说明,请查看AnimateFloat、AnimateFloatWait、AnimateFloatDelay的文档
发布于 2017-03-29 14:19:42
不要在主线程中使用任何Sleep调用,您可以在没有TTimer的情况下旋转TImage,这样:
procedure TForm1.Button1Click(Sender: TObject);
var
sText: string;
begin
Button1.Enabled := False;
sText := Button1.Text;
Button1.Text := 'Wait...';
TThread.CreateAnonymousThread(procedure
begin
while Image1.RotationAngle < 360 do begin
TThread.Synchronize(nil, procedure
begin
Image1.RotationAngle := Image1.RotationAngle + 2;
end);
Sleep(10);
end;
TThread.Synchronize(nil, procedure
begin
Button1.Text := sText;
Button1.Enabled := True;
end);
end).Start;
end;第二种解决方案:在表单中添加Anim: TFloatAnimation:
type
TForm1 = class(TForm)
...
public
Anim: TFloatAnimation;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
Anim.Enabled := False;
Image1.RotationAngle := 0;
Anim.Enabled := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Anim := TFloatAnimation.Create(Self);
Anim.Parent := Self;
Anim.Duration := 1;
Anim.StartValue := 0;
Anim.StopValue := 360;
Anim.PropertyName := 'Image1.RotationAngle';
end;https://stackoverflow.com/questions/43083156
复制相似问题