WPF特效-实现弧形旋转轮播图
? ? ? ?項(xiàng)目遇到,琢磨并實(shí)現(xiàn)了循環(huán)算法,主要處理循環(huán)替換顯示問題
? ? ? (如:12張圖組成一個(gè)圓弧,但總共有120張圖需要呈現(xiàn),如何在滑動(dòng)中進(jìn)行顯示塊的替換,并毫無卡頓)
? ? ? ?處理的自己感覺比較滿意,記錄一下。
? ? ? 2D效果圖:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ??
? ? ?2D動(dòng)態(tài)Gif效果:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ?2D思路: Canvas作為承載控件,控制顯示個(gè)數(shù),以角度作為判斷是否顯示的標(biāo)準(zhǔn)。 同時(shí)圖片以線程池或者延時(shí)加載的方式實(shí)現(xiàn)加載性能的優(yōu)化。
? ? ? ?2D循環(huán)關(guān)鍵:
? ? ?? ?private void UpdateLocation()
? ? ? ? {
? ? ? ? ? ? for (int i = 0; i < this.ElementList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? NavItem oItem = this.ElementList[i];
? ? ? ? ? ? ? ? if(oItem.Degree - this.CenterDegree >= this.TotalDegree /2d)
? ? ? ? ? ? ? ? ? ? oItem.Degree -= this.TotalDegree;
? ? ? ? ? ? ? ? else if(this.CenterDegree - oItem.Degree > this.TotalDegree / 2d)
? ? ? ? ? ? ? ? ? ? oItem.Degree += this.TotalDegree;
? ? ? ? ? ? ? ? if (oItem.Degree >= 90d && oItem.Degree < 270d) // Degree 在90-270之間的顯示
? ? ? ? ? ? ? ? ? ? this.SetElementVisiable(oItem);
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? this.SetElementInvisiable(oItem);
? ? ? ? ? ? }
? ? ? ? }
? ? ? 3D效果圖:
? ? ? ??
? ? ? 3D動(dòng)態(tài)Gif效果:
??
? ? ? ? ? ? ? ? ? ? ?
? ? ? 3D思路:以Viewport3D 作為容器,ModelVisual3D 實(shí)現(xiàn)元素塊的承載,轉(zhuǎn)動(dòng)效果通過控制Camera的Angle角度實(shí)現(xiàn)。?
? ? ? ? ? ? ? ? ? ? ? 以顯示塊構(gòu)成圓弧的角度以及Camera的旋轉(zhuǎn)角度為依據(jù)控制元素塊是否呈現(xiàn)或隱藏。
? ? ? 3D循環(huán)替換關(guān)鍵:
? ? ? ? private void DoUpdateLayout()
? ? ? ? {
? ? ? ? ? ? for (int i = 0; i < this.ElementList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? InteractivePanel3D oVisualItem = this.ElementList[i];
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? if (oVisualItem.Degree + this.CameraAngleYZm.Angle >= this.TotalDegree / 2d)
? ? ? ? ? ? ? ? ? ? oVisualItem.Degree -= this.TotalDegree;
? ? ? ? ? ? ? ? else if (oVisualItem.Degree + this.CameraAngleYZm.Angle <= -this.TotalDegree / 2d)
? ? ? ? ? ? ? ? ? ? oVisualItem.Degree += this.TotalDegree;
? ? ? ? ? ? ? ? //元素塊角度與3D場(chǎng)景旋轉(zhuǎn)角度的角度差; 角度差在定義的范圍內(nèi)則元素塊顯示,否則隱藏
? ? ? ? ? ? ? ? double dDistanceToCenter = Math.Abs(oVisualItem.Degree + this.CameraAngleY.Angle - COriginViewprotAngel);
? ? ? ? ? ? ? ? if (dDistanceToCenter <= CBoundDegree)
? ? ? ? ? ? ? ? ? ? this.SetVisualItemVisible(oVisualItem);
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? this.SetVisualItemInvisible(oVisualItem);
? ? ? ? ? ? }
? ? ? ? }
總結(jié)
以上是生活随笔為你收集整理的WPF特效-实现弧形旋转轮播图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国香港地区 DDoS- botnet
- 下一篇: 大数据(1) - 虚拟机集群搭建