【iOS】Spring Animations (彈性動畫)

来源:https://www.cnblogs.com/xjf125/archive/2020/01/04/12150345.html
-Advertisement-
Play Games

This interface shows how a spring animation can be created by specifying a “damping” (bounciness) and “response” (speed). 這個交互顯示瞭如何通過指定“阻尼”(有彈性)和“響應”( ...


  This interface shows how a spring animation can be created by specifying a “damping” (bounciness) and “response” (speed).

  這個交互顯示瞭如何通過指定“阻尼”(有彈性)和“響應”(速度)來創建spring動畫。

  

  Key Features(關鍵特性)

  1. Uses “design-friendly” parameters.(使用友好的參數)。
  2. No concept of animation duration.(沒有動畫持續時間的概念)。
  3. Easily interruptible.(容易中斷)。

  Design Theory(設計理論)

  Springs make great animation models because of their speed and natural appearance. A spring animation starts incredibly quickly, spending most of its time gradually approaching its final state. This is perfect for creating interfaces that feel responsive—they spring to life!

  彈性可以實現很好的動畫模型,因為它們的速度和自然的外觀。彈性動畫的啟動速度非常快,大部分時間都在逐漸接近其最終狀態。這對於創建感覺有響應的界面來說是非常完美的。

  A few additional reminders when designing spring animations:

  設計spring動畫時的一些額外提示:

  1. Springs don’t have to be springy. Using a damping value of 1 will create an animation that slowly comes to rest without any bounciness. Most animations should use a damping value of 1. 譯:彈簧不一定有彈性。使用阻尼值1將創建一個動畫,它會慢慢地停止,沒有任何彈性,大多數動畫應該使用阻尼值1.
  2. Try to avoid thinking about duration. In theory, a spring never fully comes to rest, and forcing a duration on the spring can cause it to feel unnatural. Instead, play with the damping and response values until it feels right. 譯:儘量避免考慮持續時間。從理論上講,彈簧永遠不會完全靜止,強迫彈簧持續一段時間會讓它感到不自然。相反,使用阻尼和響應值,直到感覺正確為止。

  3. Interruption is critical. Because springs spend so much of their time close to their final value, users may think the animation has completed and will try to interact with it again.中斷是至關重要的,因為彈性花費瞭如此多的時間來接近它們的最終價值,用戶可能認為動畫已經完成,並將再次嘗試與它交互。

   Critical Code(關鍵代碼)

  In UIKit, we can create a spring animation with a UIViewPropertyAnimatorand a UISpringTimingParameters object. Unfortunately, there is no initializer that just takes a damping and response. The closest we can get is the UISpringTimingParameters initializer that takes a mass, stiffness, damping, and initial velocity.

  在UIKit中,我們可以用UIViewPropertyAnimator和UISpringTimingParameters對象創建一個spring動畫。不幸的是,沒有一個初始化器只接受阻尼和響應。我們能得到的最接近的值是UISpringTimingParameters初始化器,它具有質量、剛度、阻尼和初始速度。

UISpringTimingParameters(mass: CGFloat, stiffness: CGFloat, damping: CGFloat, initialVelocity: CGVector)

  We would like to create a convenience initializer that takes a damping and response, and maps it to the required mass, stiffness, and damping.

  我們希望創建一個方便的初始化器,它接受阻尼和響應,並將其映射到所需的質量、剛度和阻尼。
  With a little bit of physics, we can derive the equations we need:

  有了一點物理學知識,我們就可以推導出我們需要的方程:

 

  With this result, we can create our own UISpringTimingParameters with exactly the parameters we desire.

  有了這個結果,我們就可以創建我們自己的UISpringTimingParameters,這些參數正是我們想要的。

extension UISpringTimingParameters {
    convenience init(damping: CGFloat, response: CGFloat, initialVelocity: CGVector = .zero) {
        let stiffness = pow(2 * .pi / response, 2)
        let damp = 4 * .pi * damping / response
        self.init(mass: 1, stiffness: stiffness, damping: damp, initialVelocity: initialVelocity)
    }
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Tomcat是Apache 軟體基金會(Apache Software Foundation)的Jakarta 項目中的一個核心項目,由Apache、Sun 和其他一些公司及個人共同開發而成。Tomcat 伺服器是一個免費的開放源代碼的Web 應用伺服器,屬於輕量級應用伺服器,在中小型系統和併發訪問 ...
  • 前面有寫過《MS SQL為欄位添加說明》https://www.cnblogs.com/insus/p/12106589.html 現如今,我們獲取這些欄位的描述值。 先來看一句SELECT語句: SELECT * FROM sys.extended_properties GO 如上SQL語句,雖然 ...
  • 適用環境: 資料庫版本:MySQL 5.7.26 操作系統:CentOS 7 製作思路: 將資料庫初始化和配置工作放到安裝腳本中方便定製: 1、打包MySQL應用目錄 2、不自動生成配置文件 3、不自動生成數據目錄 4、不自動初始化數據 Spec代碼: # # # MySQL參數配置 # mysql ...
  • 場景 Android佈局管理器-使用LinearLayout實現簡單的登錄視窗佈局: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103838995 幀佈局管理器FrameLayout 實現效果 註: 博客: https://b ...
  • 場景 Android佈局管理器-從實例入手學習相對佈局管理器的使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103838924 線性佈局LinearLayout,分為水平和垂直線性佈局。 實現效果如下 註: 博客: htt ...
  • 場景 AndroidStudio跑起來第一個App時新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797243 使用相對佈局RelativeLayout實現簡單的登錄提示的佈局,效果如下 註: 博客: h ...
  • 最近有一些開發朋友問我應該怎樣提升自己的能力,回想起來做了這麼久 iOS 開發,我也有過那種“讓我做一個功能實現個需求我會做,但接下來怎樣提高我不知道。”的時期,這裡嘗試列一下 iOS 開發的相關技術,再說說在學習進階上我的一些想法。 iOS 技術棧 這裡按我的理解給 iOS 相關技術分個類,以工程 ...
  • 1.壓力測試monkey 通過cmd輸入下麵命令: 表示測試com.example.phonecall應用程式,隨機發送點擊/滑動/切換事件10000次,( -v -v -v)表示信息日誌為最高級,然後列印的信息傳到F:\monkey_log\test1.txt里. 如下圖所示: 2.單元測試 2. ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...