首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在过程中旋转TImage (不使用TTimer)

在过程中旋转TImage (不使用TTimer)
EN

Stack Overflow用户
提问于 2017-03-29 10:22:37
回答 2查看 310关注 0票数 0

我试着在安卓系统上用德尔福火猴(柏林)在TButton程序中制作一个简单的TImage从一个度数旋转到另一个度数的动画,如下所示:

代码语言:javascript
复制
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时,它工作得很好。有谁知道怎么解决这个问题吗?

EN

回答 2

Stack Overflow用户

发布于 2017-03-31 22:31:09

将FMX.Ani添加到uses子句中,并在button onlick事件中使用TAnimator:

代码语言:javascript
复制
procedure TForm1.Button1Click(Sender: TObject);
begin
 Image1.RotationAngle:=0;
 TAnimator.AnimateFloat(Image1,'RotationAngle',360,1,TAnimationType.InOut, TInterpolationType.Exponential );
end;

有关参数的详细说明,请查看AnimateFloat、AnimateFloatWait、AnimateFloatDelay的文档

票数 1
EN

Stack Overflow用户

发布于 2017-03-29 14:19:42

不要在主线程中使用任何Sleep调用,您可以在没有TTimer的情况下旋转TImage,这样:

代码语言:javascript
复制
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

代码语言:javascript
复制
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;
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43083156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档