/* * 查看大图 * * 加载动画 */ public static void showAnimation(Border borderBg, Canvas currElement, DControlDto ctl, double toTranslateTransformX, double toTranslateTransformY) { //淡入 borderBg.RenderTransformOrigin = new Point(0.5, 0.5); DoubleAnimation da = new DoubleAnimation(0, borderBg.Opacity, new Duration(TimeSpan.FromMilliseconds(300))); borderBg.BeginAnimation(UIElement.OpacityProperty, da); //放大 TransformGroup group = (TransformGroup)currElement.RenderTransform; ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = new DoubleAnimation(scaleTransform.ScaleX, 1.0, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); DoubleAnimation da2 = new DoubleAnimation(scaleTransform.ScaleY, 1.0, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da2); // 平移 TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da3 = new DoubleAnimation(0, toTranslateTransformX, new Duration(TimeSpan.FromMilliseconds(300))); translateTransform.BeginAnimation(TranslateTransform.XProperty, da3); DoubleAnimation da4 = new DoubleAnimation(0, toTranslateTransformY, new Duration(TimeSpan.FromMilliseconds(300))); translateTransform.BeginAnimation(TranslateTransform.YProperty, da4); }
/* * 关闭视频 * * 动画,回到原位,移除大图 */ private void closeVideoAnimation(Canvas fullVideoCanvas, DControlDto dControlDto, CVideo cVideo) { //1.淡出 DoubleAnimation da = new DoubleAnimation(fullVideoCanvas.Opacity, 0, new Duration(TimeSpan.FromMilliseconds(100))); da.BeginTime = TimeSpan.FromMilliseconds(200); fullVideoCanvas.BeginAnimation(UIElement.OpacityProperty, da); //触摸缩放后 double backToScaleX = dControlDto.width / fullVideoCanvas.Width; double backToScaleY = dControlDto.height / fullVideoCanvas.Height; Transform transform = fullVideoCanvas.RenderTransform; TransformGroup group = (TransformGroup)fullVideoCanvas.RenderTransform; //2.缩放 ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = new DoubleAnimation(scaleTransform.ScaleX, backToScaleX, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); DoubleAnimation da2 = new DoubleAnimation(scaleTransform.ScaleY, backToScaleY, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da2); // 3.平移 TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da3 = new DoubleAnimation(translateTransform.X, 0, new Duration(TimeSpan.FromMilliseconds(300))); translateTransform.BeginAnimation(TranslateTransform.XProperty, da3); DoubleAnimation da4 = new DoubleAnimation(translateTransform.Y, 0, new Duration(TimeSpan.FromMilliseconds(300))); da4.Completed += (sender, e) => closeVideoAnimation_Completed(fullVideoCanvas, cVideo, dControlDto); translateTransform.BeginAnimation(TranslateTransform.YProperty, da4); }
/* * 关闭大图 * * 动画,回到原位,移除大图 */ public static void closeAnimation(Canvas bigImageCanvas, Border borderBg, Canvas innerCanvas, DControlDto ctl, Grid mainContainer) { //1.淡出 borderBg.RenderTransformOrigin = new Point(0.5, 0.5); DoubleAnimation da = new DoubleAnimation(borderBg.Opacity, 0, new Duration(TimeSpan.FromMilliseconds(300))); borderBg.BeginAnimation(UIElement.OpacityProperty, da); //触摸缩放后 double backToScaleX = ctl.width / innerCanvas.Width; double backToScaleY = ctl.height / innerCanvas.Height; Transform transform = innerCanvas.RenderTransform; TransformGroup group = null; if (transform is TransformGroup) { group = (TransformGroup)innerCanvas.RenderTransform; } else { group = new TransformGroup(); TranslateTransform translateTransform1 = new TranslateTransform(); MatrixTransform matrixTransform = (MatrixTransform)innerCanvas.RenderTransform; translateTransform1.X = matrixTransform.Matrix.OffsetX; translateTransform1.Y = matrixTransform.Matrix.OffsetY; group.Children.Add(translateTransform1); ScaleTransform scaleTransform1 = new ScaleTransform(); scaleTransform1.ScaleX = matrixTransform.Matrix.M11; scaleTransform1.ScaleY = matrixTransform.Matrix.M22; group.Children.Add(scaleTransform1); innerCanvas.RenderTransform = group; } //2.缩放 ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = new DoubleAnimation(scaleTransform.ScaleX, backToScaleX, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); DoubleAnimation da2 = new DoubleAnimation(scaleTransform.ScaleY, backToScaleY, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da2); // 3.平移 TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da3 = new DoubleAnimation(translateTransform.X, 0, new Duration(TimeSpan.FromMilliseconds(300))); translateTransform.BeginAnimation(TranslateTransform.XProperty, da3); DoubleAnimation da4 = new DoubleAnimation(translateTransform.Y, 0, new Duration(TimeSpan.FromMilliseconds(300))); da4.Completed += (sender, e) => closeBigImageAnimation_Completed(bigImageCanvas, mainContainer); translateTransform.BeginAnimation(TranslateTransform.YProperty, da4); }
/* * 关闭大图 * * 动画,回到原位,移除大图 */ public static void closeAnimation(Canvas frameDialogCanvas, Border borderBg, Canvas innerCanvas, DControl dControlDto, Grid mainContainer) { double scaleX = dControlDto.width / innerCanvas.Width; double scaleY = dControlDto.height / innerCanvas.Height; if (scaleX / scaleY > 2 || scaleY / scaleX > 2) { scaleX = 0.1; scaleY = 0.1; } //1.淡出 borderBg.RenderTransformOrigin = new Point(0.5, 0.5); DoubleAnimation da = new DoubleAnimation(borderBg.Opacity, 0, new Duration(TimeSpan.FromMilliseconds(300))); borderBg.BeginAnimation(UIElement.OpacityProperty, da); //2.缩放 TransformGroup group = (TransformGroup)innerCanvas.RenderTransform; // innerCanvas.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da2 = new DoubleAnimation(scaleTransform.ScaleY, scaleY, new Duration(TimeSpan.FromMilliseconds(300))); da2.Completed += (sender, e) => closeAnimation_Completed(frameDialogCanvas, innerCanvas, mainContainer); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da2); DoubleAnimation da22 = new DoubleAnimation(scaleTransform.ScaleX, scaleX, new Duration(TimeSpan.FromMilliseconds(300))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da22); // 平移 TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da31 = new DoubleAnimation(translateTransform.X, 0, new Duration(TimeSpan.FromMilliseconds(300))); translateTransform.BeginAnimation(TranslateTransform.XProperty, da31); DoubleAnimation da32 = new DoubleAnimation(translateTransform.Y, 0, new Duration(TimeSpan.FromMilliseconds(300))); translateTransform.BeginAnimation(TranslateTransform.YProperty, da32); // 淡出模式 DoubleAnimation da4 = new DoubleAnimation(innerCanvas.Opacity, 0, new Duration(TimeSpan.FromMilliseconds(300))); da4.Completed += (sender, e) => closeAnimation_Completed(frameDialogCanvas, innerCanvas, mainContainer); innerCanvas.BeginAnimation(UIElement.OpacityProperty, da4); }
/* * 3左侧移入 - 右侧移出 */ public static void TranslateXMoveOut(Border CoverBorder, int pageWidth) { CoverBorder.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5); TransformGroup group = new TransformGroup(); CoverBorder.RenderTransform = group; TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = new DoubleAnimation(0, pageWidth, new Duration(TimeSpan.FromMilliseconds(400))); da.BeginTime = TimeSpan.FromMilliseconds(0); IEasingFunction easingFunction = new SineEase() { EasingMode = EasingMode.EaseIn }; // da.EasingFunction = easingFunction; //da.AccelerationRatio = 0.2; da.Completed += (sender1, e1) => CoverBorderMoveOut_Completed(CoverBorder); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); }
private void moveIn(object sender, EventArgs e) { Int32 pageSwitchType = dPage.pageSwitchType; if (isBack && backPageSwitchType > 0) { pageSwitchType = backPageSwitchType; } if (pageSwitchType <= 0) { pageSwitchType = 1; } int pageWidth = dPage.width; if (pageWidth <= 0) { pageWidth = App.localStorage.cfg.screenWidth; } //1.默认 if (pageSwitchType == 1) { mainFrame.Background = Brushes.Transparent; return; } //2.淡入 else if (pageSwitchType == 2) { TransformGroup group = new TransformGroup(); RenderTransform = group; DoubleAnimation da = new DoubleAnimation(0, 1.0, new Duration(TimeSpan.FromMilliseconds(400))); da.BeginTime = TimeSpan.FromMilliseconds(0); IEasingFunction easingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }; da.EasingFunction = easingFunction; da.Completed += a2_Completed; BeginAnimation(UIElement.OpacityProperty, da); return; } //3.右侧移入 else if (pageSwitchType == 3) { if (isBack) { return; } TransformGroup group = new TransformGroup(); RenderTransform = group; double middlePos = pageWidth / 2; TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = new DoubleAnimation(middlePos, 0, new Duration(TimeSpan.FromMilliseconds(500))); da.BeginTime = TimeSpan.FromMilliseconds(0); IEasingFunction easingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }; da.AccelerationRatio = 0.9; // da.EasingFunction = easingFunction; da.Completed += a2_Completed; translateTransform.BeginAnimation(TranslateTransform.XProperty, da); Opacity = 0; DoubleAnimation da1 = new DoubleAnimation(0, 1.0, new Duration(TimeSpan.FromMilliseconds(100))); da1.BeginTime = TimeSpan.FromMilliseconds(0); da1.EasingFunction = easingFunction; BeginAnimation(UIElement.OpacityProperty, da1); return; } //4.右侧拉伸 else if (pageSwitchType == 4) { if (isBack) { return; } RenderTransformOrigin = new System.Windows.Point(1, 0); TransformGroup group = new TransformGroup(); RenderTransform = group; ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = new DoubleAnimation(0, 1.0, new Duration(TimeSpan.FromMilliseconds(500))); da.BeginTime = TimeSpan.FromMilliseconds(0); //da.EasingFunction = easingFunction; da.Completed += a2_Completed; scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); return; } //5.中心放大 else if (pageSwitchType == 5) { if (isBack) { return; } RenderTransformOrigin = new System.Windows.Point(0.5, 0.5); TransformGroup group = new TransformGroup(); RenderTransform = group; ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = new DoubleAnimation(0.2, 1.0, new Duration(TimeSpan.FromMilliseconds(500))); da.BeginTime = TimeSpan.FromMilliseconds(0); IEasingFunction easingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }; da.EasingFunction = easingFunction; da.Completed += a2_Completed; scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); Opacity = 0; DoubleAnimation da1 = new DoubleAnimation(0, 1.0, new Duration(TimeSpan.FromMilliseconds(100))); da1.BeginTime = TimeSpan.FromMilliseconds(0); da1.EasingFunction = easingFunction; BeginAnimation(UIElement.OpacityProperty, da1); return; } }