簡體   English   中英

使用UIDynamicAnimator水平動畫UIView

[英]Animate UIView horizontally using UIDynamicAnimator

我已經閱讀了文檔,我很尷尬地說我很困惑。

場景

我有一個UIView ,就像3個UIButtons的容器一樣。 這個容器最初是{0, 0, 35, 35} 0,0,35,35 {0, 0, 35, 35}的邊界,每個按鈕里面有相同的坐標( alpha 0)。 在用戶的特定動作上,容器將邊界更改為{0, 0, 100, 35} ,並且該按鈕分別動畫為x-origin 5,35和65,並且alpha 1,以便它們被傳播在調整大小的容器內。 我將此稱為容器的展開狀態 用戶執行相同操作,將其切換回原始合同狀態

目標

我目前正在使用[UIView animateWithDuration:]塊執行此操作,但是想使用UIDynamicAnimator添加彈性效果,這樣,當切換到展開狀態時,容器會通過反彈調整大小(調整大小一點,並彈跳回到目標邊界),按鈕也會反彈(向前移動一點,然后彈回到目標邊界)。

困惑

UIDynamicAnimatorUIDynamicBehaviorUIAttachmentBehaviorUIDynamicItem ......所有這些都讓我對UIKitDynamic理解溢出。 我想我應該使用UISnapBehavior ,但我不知道如何去做。

事實證明,使用UIDynamicAnimator ,並不需要所有其他動態動畫。 我需要的只是animateWithDuration:delay:usingSpringWithDamping: initialSpringVelocity: options: animations: completion: class method。 只需使用它代替任何簡單的animateWithDuration:方法,它就會產生我想要實現的確切行為。

示例代碼:

    [UIView animateWithDuration:0.4
                          delay:0
         usingSpringWithDamping:0.5
          initialSpringVelocity:0.5
                        options:0
                     animations:^{

                         //Animation code

                     } completion:nil];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM