{"id":4953,"date":"2018-09-02T13:18:53","date_gmt":"2018-09-02T05:18:53","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4953"},"modified":"2019-06-09T21:33:44","modified_gmt":"2019-06-09T13:33:44","slug":"%e6%95%99%e7%a8%8bqanimation-%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b%e4%b9%8b%e4%b8%80%ef%bc%9a%e4%b8%ba-tpagecontrol-%e5%88%87%e6%8d%a2%e5%8a%a0%e5%85%a5%e5%8a%a8%e7%94%bb%e6%95%88%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4953","title":{"rendered":"[\u6559\u7a0b]QAnimation \u4f7f\u7528\u6559\u7a0b\u4e4b\u4e00\uff1a\u4e3a TPageControl \u5207\u6362\u52a0\u5165\u52a8\u753b\u6548\u679c"},"content":{"rendered":"<p>\u9996\u5148\uff0cVCL \u7684 TPageControl \u662f\u6ca1\u6709\u5207\u5165\u5207\u51fa\u52a8\u753b\u7684\uff0c\u6240\u4ee5\uff0c\u8fd9\u91cc\u8981\u505a\u7684\u662f\u7ed9 VCL \u7684 TPageControl \u505a\u52a8\u753b\u652f\u6301\u3002\u5f53\u7136\uff0c\u867d\u7136\u54b1\u4eec\u8bf4\u7684\u662f QAnimation \u6559\u7a0b\uff0c\u4f46\u5173\u6ce8\u7684\u91cd\u70b9\u4e0d\u662f QAnimation\uff0c\u800c\u662f\u5982\u4f55\u7ed9 TPageControl \u6dfb\u52a0\u52a8\u753b\u6548\u679c\uff0cQAnimation \u53ea\u662f\u4e00\u4e2a\u52a8\u753b\u63a7\u5236\u5668\u800c\u5df2\uff0c\u4f60\u5b8c\u5168\u53ef\u4ee5\u7528\u81ea\u5df1\u7684 Timer \u6765\u66ff\u4ee3\u3002<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u5f53\u7136\u662f\u4e3a PageControl \u521b\u5efa N \u4e2a TabSheet \u9875\u9762\uff0c\u8fd9\u4e00\u6b65\u6211\u4eec\u7701\u7565\u8bf4\u660e\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u52a0\u5165\u52a8\u753b\u63a7\u5236\u4ee3\u7801\u3002<\/p>\n<ol>\n<li>\u5f15\u7528 qdac_ani \u5355\u5143\uff0c\u6216\u8005\u5728\u754c\u9762\u4e0a\u52a0\u4e0a\u4f60\u7684 Timer\uff0c\u7136\u540e\u5728\u4f60\u7684 Timer \u7684 OnTimer \u4e8b\u4ef6\u4e2d\u5904\u7406\u52a8\u753b\u3002<\/li>\n<li>\u6211\u8fd9\u4e2a Demo \u662f\u8981\u6c42\u4e0d\u65ad\u7684\u5207\u6362\uff0c\u7c7b\u4f3c\u7f51\u9875\u4e0a\u5e38\u89c1\u7684 slider \u6548\u679c\uff0c\u6240\u4ee5\u6211\u5728 FormCreate \u4e8b\u4ef6\u4e2d\u6dfb\u52a0\u5904\u7406\u4ee3\u7801\uff1a\n<pre class=\"lang:delphi decode:true\">unit Unit1;\n\ninterface\n\nuses\n  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,\n  System.Classes, Vcl.Graphics,\n  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, qdac_ani,\n  Vcl.Imaging.pngimage, Vcl.ExtCtrls;\n\ntype\n  TForm1 = class(TForm)\n    PageControl1: TPageControl;\n    TabSheet1: TTabSheet;\n    TabSheet2: TTabSheet;\n    Label1: TLabel;\n    Label2: TLabel;\n    Edit1: TEdit;\n    Image1: TImage;\n    procedure FormCreate(Sender: TObject);\n  private\n    { Private declarations }\n    FAnimation: IQAnimation;\n  public\n    { Public declarations }\n  end;\n\nvar\n  Form1: TForm1;\n\nimplementation\nuses qstring;\n{$R *.dfm}\n\nprocedure TForm1.FormCreate(Sender: TObject);\nvar\n  I: Integer;\nbegin\n  for I := 0 to PageControl1.PageCount - 1 do\n    PageControl1.Pages[I].TabVisible := false;\n  PageControl1.ActivePage := TabSheet1;\n  \/\/\u521b\u5efa\u52a8\u753b\u63a7\u5236\u5668\n  FAnimation := CreateAnimation(\n    procedure(Sender: IQAnimation; AEvent: TQAnimationEvent)\n    var\n      APage: TTabSheet;\n    begin\n      case AEvent of\n        GotoTime:\n          begin\n            \/\/\u56e0\u4e3a\u52a8\u753b\u662f\u5c06\u4e0b\u4e00\u9875\u5207\u5165\uff0c\u6240\u4ee5\u53d6\u5f53\u524d\u6d3b\u52a8\u9875\u7684\u4e0b\u4e00\u9875\u8fdb\u884c\u5904\u7406\n            APage := PageControl1.Pages[(PageControl1.ActivePageIndex + 1)\n              mod PageControl1.PageCount];\n            APage.SetBounds(PageControl1.ActivePage.Left,APage.Height - Trunc(APage.Height *\n              Sender.NormalizedTime),PageControl1.ActivePage.Width,PageControl1.ActivePage.Height);\n          end;\n        EnterDelay:\n          begin\n            APage := PageControl1.Pages[(PageControl1.ActivePageIndex + 1)\n              mod PageControl1.PageCount];\n            APage.Align := alClient;\n            PageControl1.ActivePage := APage;\n          end;\n        ExitDelay:\n          begin\n             \/\/\u56e0\u4e3a\u52a8\u753b\u662f\u5c06\u4e0b\u4e00\u9875\u5207\u5165\uff0c\u6240\u4ee5\u53d6\u5f53\u524d\u6d3b\u52a8\u9875\u7684\u4e0b\u4e00\u9875\u8fdb\u884c\u5904\u7406\n            APage := PageControl1.Pages[(PageControl1.ActivePageIndex + 1)\n              mod PageControl1.PageCount];\n            \/\/VCL\u7684 TabSheet \u9ed8\u8ba4\u662falClient\uff0c\u90a3\u6837\u6ca1\u6cd5\u8c03\u6574\u5750\u6807\uff0c\u6240\u4ee5\u6539\u4e0b\n            APage.Align := alNone;\n            \/\/\u4e0d\u53ef\u89c1\u9875\u5b9e\u9645\u4e0a\u662f\u9690\u85cf\u7684\uff0c\u8bbe\u7f6e\u4e3atrue\u663e\u793a\u51fa\u6765\n            APage.Visible := true;\n            \/\/\u52a8\u753b\u9875\u5207\u5230\u524d\u9762\uff0c\u540e\u9762\u8c01\u4e5f\u4e0d\u77e5\u9053\u5440\n            APage.BringToFront;\n          end;\n      end;\n    end);\n  FAnimation.Duration := 1;\/\/\u52a8\u753b\u65f6\u957f\u8bbe\u7f6e\u4e3a1\u79d2\n  FAnimation.Interpolation := TQInterpolationType.Bounce;\/\/\u52a8\u753b\u65b9\u5f0f\u8bbe\u7f6e\u4e3a\u5f39\u8df3\n  FAnimation.DelayTime := 5;\/\/\u52a8\u753b\u5ef6\u8fdf\u95f4\u9694\u8bbe\u7f6e\u4e3a5\u79d2\n  FAnimation.Loop := true;\/\/\u5faa\u73af\n  FAnimation.Start;\/\/\u542f\u52a8\u52a8\u753b\nend;<\/pre>\n<p>QAnimation \u63d0\u4f9b\u4e86\u4e00\u4e2a CreateXXAnimation \u7684\u4e00\u7ec4\u63a5\u53e3\u51fd\u6570\uff0c\u65b9\u4fbf\u521b\u5efa\u4e0d\u540c\u7c7b\u578b\u7684\u52a8\u753b\u3002\u56e0\u4e3a\u8fd9\u4e2a\u63a7\u5236\u64cd\u4f5c\u76f8\u5bf9\u590d\u6742\u4e00\u4e9b\uff0c\u6240\u4ee5\u6211\u76f4\u63a5\u7528\u4e86 CreateAnimation\uff0c\u81ea\u5df1\u53bb\u5b9e\u73b0\u5bf9\u9875\u9762\u5c5e\u6027\u7684\u63a7\u5236\u3002\u7136\u540e\u4e0a\u9762\u7684\u52a8\u753b\u63a7\u5236\u53c2\u6570\u90fd\u6709\u8bf4\u660e\uff0c\u6211\u5c31\u4e0d\u7f00\u8ff0\uff0c\u81ea\u5df1\u770b\u4e0b\u5c31\u597d\u3002\u91cd\u70b9\u5927\u5bb6\u5173\u6ce8\u4e0b\u5bf9\u9875\u9762\u5207\u6362\u7684\u5904\u7406\uff0c\u5728\u6211\u4eec\u5f00\u59cb\u5207\u5165\u65b0\u9875\u65f6\uff0c\u8981\u5c06\u65b0\u9875\u7684 Align \u8bbe\u7f6e\u4e3a alNone\uff0c\u5426\u662f\u4f60\u8c03\u6574\u5750\u6807\u662f\u52a8\u4e0d\u8d77\u6765\u7684\uff0c\u7136\u540e\u8fd8\u9700\u8981\u5c06\u8981\u65b0\u9875\u7ed9\u63d0\u5230\u6700\u524d\u663e\u793a\uff0c\u5426\u5219\u5728\u540e\u8fb9\u7528\u6237\u4e5f\u770b\u4e0d\u5230\uff0c\u5bf9\u4e0d\u5bf9\uff1f\u81f3\u4e8e\u52a8\u753b\u8fc7\u7a0b\u4e2d\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u76f4\u63a5\u8c03\u6574\u7684\u9876\u90e8\u7684\u5750\u6807\uff0c\u7136\u540e\u5b9e\u73b0\u7684\u52a8\u753b\u65b9\u5f0f\u662f\u5f39\u8df3\u7684\u6548\u679c\u3002\u770b\u4e00\u4e0b\u5b9e\u9645\u8fd0\u884c\u7684\u6548\u679c\uff1a<br \/>\n<a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2018\/09\/qani.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4954\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2018\/09\/qani.gif\" alt=\"\" width=\"574\" height=\"306\" \/><\/a><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2018\/09\/qani.gif\"><br \/>\n<\/a>QAnimation \u63d0\u4f9b\u7684\u989d\u5916\u52a8\u753b\u63a7\u5236\u5355\u5143\u5305\u542b\u4e0b\u9762\u7684\u51fd\u6570\uff0c\u89c1\u540d\u77e5\u4e49\uff0c\u4e0d\u505a\u591a\u8bf4\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">\/\/ \u6700\u7b80\u5355\u7684\u7528\u6237\u81ea\u5b9a\u4e49\u5904\u7406\u52a8\u753b\nfunction CreateAnimation(ACallback: TQAnimationNotifyCallback)\n  : IQAnimation; overload;\nfunction CreateAnimation(ACallback: TQAnimationNotifyEvent)\n  : IQAnimation; overload;\n\/\/ \u6d6e\u70b9\u52a8\u753b\u5904\u7406\nfunction CreateFloatAnimation(ACallback: TQAnimationNotifyCallback)\n  : IQFloatAnimation; overload;\nfunction CreateFloatAnimation(ACallback: TQAnimationNotifyEvent)\n  : IQFloatAnimation; overload;\n\/\/ \u6574\u6570\u52a8\u753b\u5904\u7406\nfunction CreateIntAnimation(ACallback: TQAnimationNotifyCallback)\n  : IQIntAnimation; overload;\nfunction CreateIntAnimation(ACallback: TQAnimationNotifyEvent)\n  : IQIntAnimation; overload;\n\/\/ \u5e03\u5c14\u52a8\u753b\u5904\u7406\nfunction CreateBooleanAnimation(ACallback: TQAnimationNotifyCallback): IQBoolAnimation; overload;\nfunction CreateBooleanAnimation(ACallback: TQAnimationNotifyEvent): IQBoolAnimation; overload;\n\/\/ \u989c\u8272\u52a8\u753b\u5904\u7406\nfunction CreateColorAnimation(ACallback: TQAnimationNotifyCallback)\n  : IQColorAnimation; overload;\nfunction CreateColorAnimation(ACallback: TQAnimationNotifyEvent)\n  : IQColorAnimation; overload;\nfunction CreateAlphaColorAnimation(ACallback: TQAnimationNotifyCallback)\n  : IQAlphaColorAnimation; overload;\nfunction CreateAlphaColorAnimation(ACallback: TQAnimationNotifyEvent)\n  : IQAlphaColorAnimation; overload;\n\n\/\/ \u7528\u6237\u81ea\u5b9a\u4e49\u63a7\u5236\u7279\u5b9a\u5c5e\u6027\u7684\u52a8\u753b\uff0c\u5177\u4f53\u7684\u9879\u76ee\u7684\u503c\u7531\u7528\u6237\u81ea\u884c\u51b3\u5b9a\nfunction CreatePropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyCallback): IQPropertyAnimation; overload;\nfunction CreatePropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyEvent): IQPropertyAnimation; overload;\n\nfunction CreateIntPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyCallback): IQIntAnimation; overload;\nfunction CreateIntPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyEvent): IQIntAnimation; overload;\n\nfunction CreateFloatPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyCallback): IQFloatAnimation; overload;\nfunction CreateFloatPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyEvent): IQFloatAnimation; overload;\n\nfunction CreateColorPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyCallback): IQColorAnimation; overload;\nfunction CreateColorPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyEvent): IQColorAnimation; overload;\n\nfunction CreateAlphaColorPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyCallback): IQAlphaColorAnimation; overload;\nfunction CreateAlphaColorPropertyAnimation(AObject: TObject; APropPath: String;\n  ACallback: TQAnimationNotifyEvent): IQAlphaColorAnimation; overload;<\/pre>\n<\/li>\n<\/ol>\n<p>\u7b2c\u4e09\u6b65\uff1a\u7f16\u8bd1\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<p>\u53e6\u5916\uff0cQAnimation \u4e0d\u662f\u514d\u8d39\u7684\uff0c\u4ef7\u683c\u6682\u5b9a 99 \u5143\uff0cFMX+VCL \u540c\u65f6\u652f\u6301\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e00\u5957\u4ee3\u7801\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u5b83\u662f FMX.Ani \u7684\u589e\u5f3a\u7248\uff0c\u5982\u679c\u5fc3\u75bc\u7684\u8bdd\uff0c\u76f4\u63a5\u81ea\u5df1\u53c2\u8003 FMX.Ani \u5355\u5143\u5199\u4e0b\u5c31\u597d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0cVCL \u7684 TPageContro [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","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":[8,603],"tags":[519,756,475,483,757],"class_list":["post-4953","post","type-post","status-publish","format-standard","hentry","category-delphi","category-603","tag-pagecontrol","tag-slider","tag-475","tag-483","tag-757"],"views":4667,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4953","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=4953"}],"version-history":[{"count":3,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4953\/revisions"}],"predecessor-version":[{"id":5093,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4953\/revisions\/5093"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}