带旋转动画的三维界面视图

本文展示了如何创建一个可旋转的三维界面效果,类似QQ 2013登陆界面动画。用户可以通过键盘左右箭头控制界面旋转。源代码中使用KeyBinding绑定键盘事件,定义了向左和向右旋转的命令,并利用三维材料构建UI。
摘要由CSDN通过智能技术生成

今天,给大家分享我刚做好的可旋转的三维界面效果,不打算过多介绍,可以看看下面几个图片。

 

 

 

 

 

其实,如果把这个程序的窗口变成透明,就可以做出QQ 2013的登陆界面动画效果了。

把这个例子运行后,通过键盘上的左,右箭键来控制旋转的方向。

 

这里的快捷键,我使用了KeyBinding类来设置,另外,自定义了两个命令,分别执行向左转和向右转的动画。

    /// <summary>
    /// 向前移动
    /// </summary>
    public class ForwCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            if (parameter == null)
            {
                return false;
            }
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            AxisAngleRotation3D rot = parameter as AxisAngleRotation3D;
            DoubleAnimation d = new DoubleAnimation();
            d.Duration = new Duration(TimeSpan.FromMilliseconds(800));
            d.By = 90d;
            rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, d, HandoffBehavior.Compose);
        }
    }
    /// <summary>
    /// 向后移动
    /// </summary>
    public class BackCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            if (parameter == null)
            {
                return false;
            }
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            AxisAngleRotation3D rot = parameter as AxisAngleRotation3D;
            DoubleAnimation d = new DoubleAnimation();
            d.By = -90d;
            d.Duration = new Duration(TimeSpan.FromMilliseconds(800));
            rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, d, HandoffBehavior.Compose);
        }
    }


然后将其应用到主窗口类中。

            // 设置快捷键
            KeyBinding forwBind = new System.Windows.Input.KeyBinding();
            forwBind.Command = new ForwCommand();
            forwBind.CommandParameter = ar;
            forwBind.Key = System.Windows.Input.Key.Right;
            this.InputBindings.Add(forwBind);
            KeyBinding backBind = new System.Windows.Input.KeyBinding();
            backBind.Command = new BackCommand();
            backBind.CommandParameter = ar;
            backBind.Key = System.Windows.Input.Key.Left;
            this.InputBindings.Add(backBind);


至于UI,就参考源代码中的XAML,主要用到了三维材料。

稍后我把源代码上传到资源区。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值