{"id":4446,"date":"2017-02-15T15:19:22","date_gmt":"2017-02-15T07:19:22","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4446"},"modified":"2017-02-15T15:19:22","modified_gmt":"2017-02-15T07:19:22","slug":"fmx-delphi-%e4%b8%ad-tanimation-%e8%ae%be%e8%ae%a1%e7%9a%84%e5%87%a0%e7%82%b9%e5%80%bc%e5%be%97%e5%95%86%e6%a6%b7%e7%9a%84%e5%9c%b0%e6%96%b9","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4446","title":{"rendered":"[FMX] Delphi \u4e2d TAnimation \u8bbe\u8ba1\u7684\u51e0\u70b9\u503c\u5f97\u5546\u69b7\u7684\u5730\u65b9"},"content":{"rendered":"<p>\u5728 FMX \u4e2d\uff0c\u52a8\u753b\u662f\u5f88\u597d\u7528\u7684\u4e00\u4e2a\u4e1c\u897f\uff0c\u4f46\u662f FMX \u52a8\u753b\u7684\u57fa\u7c7b TAnimation \u7684\u8bbe\u8ba1\uff0c\u5728\u6211\u770b\u6765\u6709\u4e00\u70b9\u503c\u5f97\u5546\u69b7\uff0c\u6211\u4eec\u6765\u770b Start \u51fd\u6570\u7684\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">procedure TAnimation.Start;\r\nvar\r\n  Control: IControl;\r\n  SaveDuration: Single;\r\nbegin\r\n  if not FLoop then\r\n    FTickCount := 0;\r\n  if Supports(Parent, IControl, Control) and (not Control.Visible) then\r\n    Exit;\r\n  if AutoReverse then\r\n  begin\r\n    if Running then\r\n      FInverse := FSavedInverse\r\n    else\r\n      FSavedInverse := FInverse;\r\n  end;\r\n  if (Abs(FDuration) &lt; 0.001) or (Root = nil) or (csDesigning in ComponentState) then\r\n  begin\r\n    { immediate animation }\r\n    SaveDuration := FDuration;\r\n    try\r\n      FDelayTime := 0;\r\n      FDuration := 1;\r\n      if FInverse then\r\n        FTime := 0\r\n      else\r\n        FTime := FDuration;\r\n      FRunning := True;\r\n      ProcessAnimation;\r\n      DoProcess;\r\n      FRunning := False;\r\n      FTime := 0;\r\n      DoFinish;\r\n    finally\r\n      FDuration := SaveDuration;\r\n    end;\r\n  end\r\n  else\r\n  begin\r\n    FDelayTime := FDelay;\r\n    FRunning := True;\r\n    if FInverse then\r\n      FTime := FDuration\r\n    else\r\n      FTime := 0;\r\n    if FDelay = 0 then\r\n    begin\r\n      FirstFrame;\r\n      ProcessAnimation;\r\n      DoProcess;\r\n    end;\r\n\r\n    if AniThread = nil then\r\n      FAniThread := TAniThread.Create;\r\n\r\n    TAniThread(AniThread).AddAnimation(Self);\r\n    if not AniThread.Enabled then\r\n      Stop\r\n    else\r\n      FEnabled := True;\r\n  end;\r\nend;<\/pre>\n<p>\u6ce8\u610f\u4e24\u4e2a\u5730\u65b9\uff1a<\/p>\n<p>\u7b2c\u4e00\u4e2a\u5730\u65b9\uff1a<\/p>\n<blockquote>\n<pre class=\"lang:delphi decode:true\">if Supports(Parent, IControl, Control) and (not Control.Visible) then\r\n    Exit;<\/pre>\n<p>\u4e2a\u4eba\u8ba4\u4e3a\u52a8\u753b\u5bf9\u8c61\u7684\u57fa\u7c7b\u5e76\u4e0d\u9002\u5408\u4e0e\u63a7\u4ef6\u505a\u5fc5\u9700\u7684\u5173\u8054\uff0c\u56e0\u4e3a\u6211\u4eec\u6709\u53ef\u80fd\u53ea\u662f\u8981\u8ba9\u5176\u4e00\u4e2a\u52a8\u753b\u7684\u542f\u52a8\u5668\u800c\u5df2\uff0c\u81ea\u5df1\u53bb\u505a\u4e00\u4e9b\u989d\u5916\u7684\u5de5\u4f5c\u5b9e\u73b0\u52a8\u753b\uff0c\u663e\u793a\uff0c\u52a0\u4e0a\u8fd9\u4e24\u4e2a\u5224\u65ad\u5e76\u4e0d\u5408\u9002\u3002\u8fd9\u4e24\u4e2a\u5224\u65ad\u66f4\u9002\u5e94\u653e\u5728\u4e0b\u4e00\u7ea7\u7684\u5b50\u7c7b\u4e2d\u5b9e\u73b0\uff0c\u5982\u53eb TControlAnimation\uff0c\u7136\u540e\u624d\u53bb\u68c0\u67e5\u8fd9\u4e9b\u4e1c\u897f\u3002<\/p><\/blockquote>\n<p>\u7b2c\u4e8c\u4e2a\u5730\u65b9\uff1a<\/p>\n<blockquote>\n<pre class=\"lang:delphi decode:true\">if (Abs(FDuration) &lt; 0.001) or (Root = nil) or (csDesigning in ComponentState) then<\/pre>\n<p>\u540c\u6837\u7684\uff0c\u8fd9\u91cc\u68c0\u67e5 Root \u6211\u89c9\u5f97\u4e5f\u6ca1\u5565\u5927\u5fc5\u8981\uff0c\u57fa\u7c7b\u4e0d\u5e94\u8be5\u7ba1\u8fd9\u4e8b\u3002<\/p><\/blockquote>\n<p>\u8fd9\u4e24\u70b9\u5730\u65b9\uff0c\u662f\u6211\u89c9\u5f97\u5b98\u65b9\u8bbe\u8ba1\u8fc7\u5ea6\u7684\u5730\u65b9\uff0c\u6bd5\u7adf\u505a\u4e00\u4e2a\u52a8\u753b\u7684\u8c03\u5ea6\u57fa\u7c7b\uff0c\u66f4\u591a\u7684\u4e8b\u8fd8\u662f\u5e94\u8be5\u4ea4\u7ed9\u5b50\u7c7b\u6765\u505a\u3002<\/p>\n<p>\u5206\u4eab\u4e00\u6bb5\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">uses FMX.utils,FMX.Ani;\r\ntype\r\nTCustomFloatAnimation = class(TAnimation)\r\n  private\r\n    procedure SetCurrentValue(const Value: Single);\r\n  protected\r\n    FStartValue, FStopValue, FCurrentValue: Single;\r\n    FStartFromCurrent: Boolean;\r\n    procedure ProcessAnimation; override;\r\n  published\r\n    property StartValue: Single read FStartValue write FStartValue nodefault;\r\n    property StartFromCurrent: Boolean read FStartFromCurrent\r\n      write FStartFromCurrent default False;\r\n    property StopValue: Single read FStopValue write FStopValue\r\n      stored True nodefault;\r\n  public\r\n    property CurrentValue: Single read FCurrentValue write SetCurrentValue;\r\n  end;\r\n\r\n{ TCustomFloatAnimation }\r\n\r\nprocedure TCustomFloatAnimation.ProcessAnimation;\r\nbegin\r\n  inherited;\r\n  FCurrentValue := InterpolateSingle(StartValue, StopValue, NormalizedTime);\r\nend;\r\n\r\nprocedure TCustomFloatAnimation.SetCurrentValue(const Value: Single);\r\nvar\r\n  AMin, AMax: Single;\r\nbegin\r\n  if FCurrentValue &lt;&gt; Value then\r\n  begin\r\n    if StartValue &lt; StopValue then\r\n    begin\r\n      AMin := StartValue;\r\n      AMax := StopValue;\r\n    end\r\n    else\r\n    begin\r\n      AMin := StopValue;\r\n      AMax := StartValue;\r\n    end;\r\n    if Value &lt; AMin then\r\n      FCurrentValue := AMin\r\n    else if Value &gt; AMax then\r\n      FCurrentValue := AMax\r\n    else\r\n      FCurrentValue := Value;\r\n  end;\r\nend;<\/pre>\n<p>\u8fd9\u4e2a\u662fTFloatAnimation\u7684\u975e\u5fc5\u9700\u7ed1\u5b9a\u5c5e\u6027\u7684\u7248\u672c\uff0c\u5728 OnProcess \u4e8b\u4ef6\u4e2d\u5904\u7406\u52a8\u753b\u6548\u679c\u3002\u4f46\u7531\u4e8e\u4e0a\u9762\u6240\u8bf4\u7684\u6743\u9650\uff0c\u4f60\u521b\u5efa\u7684\u8fd9\u4e2a\u5b50\u7c7b\u5b9e\u73b0\uff0c\u5fc5\u9700\u6307\u5b9a\u5b83\u7684 Root \u624d\u80fd\u5b9e\u73b0\u975e\u4e00\u6b21\u6027\u52a8\u753b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 FMX \u4e2d\uff0c\u52a8\u753b\u662f\u5f88\u597d\u7528\u7684\u4e00\u4e2a\u4e1c\u897f\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,21],"tags":[],"class_list":["post-4446","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-misc"],"views":5175,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4446"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4446\/revisions"}],"predecessor-version":[{"id":4447,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4446\/revisions\/4447"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}