动态UI心得一(CSharp)


version :  1.1

time :  20170523 12:30

author :  秋后夜雨coconut9325的博客

虽然不是什么大工程,但是依然保留所有权


在工作了一定时间之后,你会发现静态 UI 实在是让人受不了了!!!

所以接下来,我将对动态UI进行研究,给自己的工作时间予以肯定,以及提高兴趣。


在我们平常生活接触过的软件当中,我们发现了很多动态的控件。

例如:

1.展开折叠,在展开或收起控件时的动画效果。

2.进入结束,在进入或者结束某一场景、软件时的动画效果。

3.放大缩小,在放大或缩小地图时的动画效果。

4.滑动移动,在自定义slider中,自定义控件的滑动移动。

因为快速打的第一篇原创,一下没想到更多的动态信息,待以后补充,更欢迎留言讨论。

在开始之前,我们要清楚认识到物理学的重要性,因为这可以帮助我们设计UI更加贴近生活规律,或者说更加逼真,让你的UI不再干枯无味。

环境:CSharp (.Net framework 4.0)

#region Fields & Variants & model
        // GroupBoxFilter  move distance.
        private int moveDistanceX = 705;
        // GroupBoxFilter  move distance.
        private int moveDistanceY = 165;
        // GroupBoxFilter begin move Point (X,Y). final move Distance (X,Y).
        private Point beginPoint = new Point(0, 0);
        private Point finalPoint = new Point(0, 0);
        // Simulation range.
        private const int curvesAccuracy = 3;
        private const decimal startCurves = -5.0m;  // normally not change
        // Simulation curves.
        private int moveCurves = 0;
        private const decimal curvesSpeed = 0.1m;
        private const int curvesRange = (int)((0 - startCurves * 2) / curvesSpeed) + 1;
        private double[] curvesArray = new double[curvesRange];
        #endregion

初始化:

private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                InitUI();
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.ToString());
#endif
                throw;
            }
        }

        public void InitUI()
        {
            // Init simulation curves
            for (int i = 0; i < curvesRange; i++)
            {
                if (i == 0)
                    curvesArray[i] = 0;
                else if (i + 1 >= curvesRange)
                    curvesArray[i] = 1;
                else
                    curvesArray[i] = Math.Round(((Math.Tanh((double)startCurves + (double)curvesSpeed * i) + 1) / 2), curvesAccuracy, MidpointRounding.AwayFromZero);
            }
        }
折叠展开按钮:
private void btnFold_Click(object sender, EventArgs e)
        {
            if (groupBoxFilter.Width < this.Width / 2)
            {
                // move to right.
                beginPoint = new Point(groupBoxFilter.Width, groupBoxFilter.Height);
                finalPoint = new Point(groupBoxFilter.Width + moveDistanceX, groupBoxFilter.Height + moveDistanceY);
                tmFold.Enabled = true;
            }
            else
            {
                // move to left.
                beginPoint = new Point(groupBoxFilter.Width, groupBoxFilter.Height);
                finalPoint = new Point(groupBoxFilter.Width - moveDistanceX, groupBoxFilter.Height - moveDistanceY);
                tmFold.Enabled = true;
            }
        }
定时器(100ms):

private void tmFold_Tick(object sender, EventArgs e)
        {
            string foldString = "Fold";
            double movePercent = curvesArray[moveCurves];
            Point smallChange = new Point(1, 1);
            Point finalMoveDistance = new Point(Math.Abs(finalPoint.X - beginPoint.X), Math.Abs(finalPoint.Y - beginPoint.Y));
            Point nowMoveDistance = new Point(Math.Abs(groupBoxFilter.Width - beginPoint.X), Math.Abs(groupBoxFilter.Height - beginPoint.Y));

			// calculate smallChange to prepare moving.
            if (groupBoxFilter.Width == finalPoint.X)
                smallChange.X = 0;
            else
                smallChange.X = (int)(finalMoveDistance.X * curvesArray[moveCurves] - nowMoveDistance.X);
            if (groupBoxFilter.Height == finalPoint.Y)
                smallChange.Y = 0;
            else
                smallChange.Y = (int)(finalMoveDistance.Y * curvesArray[moveCurves] - nowMoveDistance.Y);
			// begin move.
            if (beginPoint.X < this.Width / 2)
            {
                //move to right.
                groupBoxFilter.Size = new Size(groupBoxFilter.Width + smallChange.X, groupBoxFilter.Height + smallChange.Y);
                int moveBtn = (groupBoxFilter.Height - btnFold.Height) / 2 + 4;
                btnFold.Location = new Point(btnFold.Location.X, moveBtn);
                foldString = "Fold";
            }
            else
            {
                //move to left.
                groupBoxFilter.Size = new Size(groupBoxFilter.Width - smallChange.X, groupBoxFilter.Height - smallChange.Y);
                int moveBtn = (groupBoxFilter.Height - btnFold.Height) / 2 + 4;
                btnFold.Location = new Point(btnFold.Location.X, moveBtn);
                foldString = "Unfold";
            }
            // move Curves.
            if (moveCurves == curvesRange - 1)
                moveCurves = 0;
            else
                moveCurves++;
            // end move.
            if (groupBoxFilter.Width == finalPoint.X && groupBoxFilter.Height == finalPoint.Y)
            {
                moveCurves = 0;
                btnFold.Text = foldString;
                this.tmFold.Enabled = false;
            }
        }



建议定时器时间参数与CurvesSpeed参数稍稍相互调节一下,即可看到连贯的效果


动态设计:

曲线采用的是tanh函数(Time/Distance),模拟加速度的逐渐增加及减少的物理运动。



动态效果图:




version :  1.1

time :  20170523 12:30

author :  秋后夜雨coconut9325的博客



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
漂亮的ComponentArtWebUI及Demo源码 产品特征: 先进的用户界面控件套装:为高级Web应用程序开发提供了16个优质的用户界面控件。 专为ASP.NET而设计:为三个先进且更强大的框架而设计:ASP.NET 1.0, ASP.NET 2.0和ASP.NET AJAX。 强大的客户端呈现技术:行业中最先进的Web用户界面技术。 深入整合ASP.NET AJAX:最理想的完全应用AJAX框架的控件。 全面的帮助文档和技术支持:提供了完善的产品在线帮助文档和全面的技术支持资源。 企业级服务和培训:为企业级项目开发定制专门的产品咨询和培训服务。 灵活的产品授权:针对开发者,服务和企业级应用提供不同的授权方式。 ComponentArt Web.UI 2007.1 更新信息 ComponentArt Web.UI 2007.1 版本中发布了三个最新的控件: ToolBar for ASP.NET ComboBox for ASP.NET Dialog for ASP.NET 以下为Web.UI组件2007.1版本中新增的功能特征: ComponentArt Grid 可以在Callback模式中缓存页面 (CallbackCachingEnabled和CallbackCacheSize属性)。 可在Callback模式中预加载页面到缓存中 (CallbackCacheLookAhead属性)。 页面在滑动条经过时可提取页面 (SliderFetchDelay属性)。 客户端滚动事件。 客户端beforeCallback事件。 ColumnResizeRedistributeWidth属性用于控制缩放状态。 ComponentArt Menu 引入(已选)checking和(未选)unchecking项的概念。允许菜单项成为复选框或者单元按钮。 引入(图标透明度)IconVisibility的概念。可使图标只在该项被选中或该项根目录时显示。 添加更多对上下文菜单扩展的控制:(TopGroupExpandDirection, TopGroupExpandOffsetX, TopGroupExpandOffsetY)。 增加了ExpandDisabledItems的布尔值属性。 改进了IE7中的元素覆盖运算法则,优化其执行性能。 ComponentArt MultiPage 增加了IE转换效果 (Transition, TransitionDuration属性)。 Web.UI 2007.1 版本没有进行整体框架的改变,只是在Web.UI 2006.2的基础上进行了改进,所以通过最新的ComponentArt.Web.UI.dll可以很方便的对之前的应用程序进行编译。 ComponentArt Web.UI是全球知名的ASP.NET用户界面控件包,它提供了ComponentArt独特的界面呈现技术,支持强大的AJAX技术,可以为您提供最先进的ASP.NET Web用户界面。ComponentArt Web.UI专为ASP.NET框架设计,它包含16个支持AJAX技术的优质用户界面控件,并可应用在ASP.NET 1.0, ASP.NET 2.0, ASP.NET AJAX框架中。 2008年3月27日,专注于ASP.NET Web.UI及Charting控件开发的ComponentArt又发布了Web.UI的最一代版本:2008.1。该版本有四个框架平台:ASP.NET 1.0、ASP.NET 2.0、ASP.NET Ajax,还有当然是最新的.NET框架支持的ASP.NET 3.5了。 2008.1不仅对其代码的运行效率进行了优化,还最增了一个大家期盼已久的成员:Upload。上传空间虽已不是罕见的东东,可是ComponentArt提供的这款不会让你和你的开发团队失望的。 更主要的是ASP.NET 3.5的版本的发布的,同样,特性和功能都具备的同时,也加入了对LINQ的高度支持。这样,ASP.NET 3.5的开发人员也可以享用到这份大餐喽~ Advanced User Interface Control Suite: Includes 19 Premium User Interface controls for development of sophisticated web applications. Built for ASP.NET: Available in four progressively more powerful framework builds: ASP.NET 1.0, ASP.NET 2.0, ASP.NET AJAX and ASP.NET 3.5. Powerful Client-side Rendering Technology: Featuring the most advanced web user interface technology in the industry. Deepest ASP.NET AJAX Integration: The first true controls to fully exploit the most advanced AJAX framework available. Comprehensive Documentation and Support: Featuring complete product documentation online and all-inclusive technical support resources. Enterprise Consulting and Training: Customized consulting and training services are offered to support Enterprise development projects involving larger teams of developers. Flexible Licensing: Available at Developer, Subscription and Enterprise levels. ComponentArt Web.UI 包含以下用户界面控件 Calendar (日历) Grid (表格) Rotator (旋转器) TabStrip (标签) CallBack (回调) Menu (菜单) SiteMap (地图) ToolBar (工具条) ComboBox (组合框) MultiPage (分页) Snap (抓取) TreeView (树形列表) Dialog (对话框) NavBar (导航条) Splitter (框架分离) WebChart Lite (图表) 如果涉及到安装序列号,请填写:3JKX6-YJW6X-GJJDP app_data为应用到的Sql和Access数据库文件 documentation下为官方的相关文档 DllCode下为控件的源码

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值