FireMonkey Mobile中的卡片翻转动画

时间:2014-04-29 07:16:11

标签: image delphi animation firemonkey flip

我想要实现使用Embarcadero XE6为iPhone和Android开发FireMonkey移动应用程序的翻转动画效果

我已经为Embarcadero XE6创建了Delphi的效果:

Playing card flip animation

可以将源代码从Delphi转换为FireMonkey Mobile吗?

2 个答案:

答案 0 :(得分:2)

是的,这是可能的。但我所知道的并不是自动的。你必须手动完成它。

看看firemonkey的帮助 http://docwiki.embarcadero.com/CodeExamples/XE3/en/FMX.MetropolisUIFlipViewDemo_Sample

它看起来像什么.. http://www.youtube.com/watch?v=SxhAvw37lEw

答案 1 :(得分:0)

这段代码可能会让您使用Firemonkey进行3D卡片翻转。

procedure TFormMain.Flip( aTabControl: TTabControl; aFront, aBack: TTabItem; aBkColor: TAlphaColor; aDirection: TFlipDirection ) ;
var
  Viewport: TViewport3D;
  R: TRectangle3D;
  bmpFront: TBitmap;
  bmpBack: TBitmap;
  matFront: TTextureMaterialSource;
  matBack: TTextureMaterialSource;
  Depth: extended;
  Angle: extended;
begin
  // Create a viewport and let it overlap aControl
  Viewport := TViewport3D.Create(nil);
  Viewport.BoundsRect := aTabControl.BoundsRect;
  Viewport.Position.X := aTabControl.Position.X;
  Viewport.Position.Y := aTabControl.Position.Y;
  Viewport.Color := aBkColor;
  Viewport.Parent := Self;

  // Create a flat 3d-rectangle and let it fully contain the Viewport
  R := TRectangle3D.Create(Viewport);
  R.Parent := Viewport;
  R.Projection := TProjection.Screen;
  R.Width := Viewport.Width;
  R.Height := Viewport.Height;
  R.Depth := 0;

  // Create a texture for the front and the back
  matFront := TTextureMaterialSource.Create(Viewport);
  aTabControl.ActiveTab := aFront;
  matFront.Texture := aTabControl.MakeScreenshot;
  R.MaterialSource := matFront;

  matBack := TTextureMaterialSource.Create(Viewport);
  aTabControl.ActiveTab := aBack;
  matBack.Texture := aTabControl.MakeScreenshot;
  matBack.Texture.FlipHorizontal;
  R.MaterialBackSource := matBack;

  // Do the flip
  Depth := 10;
  R.Position.Z := Depth;
  case aDirection of
    fdNormal : Angle := 180;
    fdReverse: Angle := -180;
  end;
  R.AnimateFloatWait( 'Position.Z', Depth, 0.1, TAnimationType.InOut, TInterpolationType.Linear );

  R.AnimateFloatWait( 'RotationAngle.Y', Angle, 0.5,
                      TAnimationType(cbAnimationType.ItemIndex),   {best is In}
                      TInterpolationType(cbInterpolationType.ItemIndex) );  {best is Back}
  R.AnimateFloatWait( 'Position.Z', 0, 0.1, TAnimationType.InOut, TInterpolationType.Linear);

  // Clear viewport and its children
  Viewport.DisposeOf;
end;