Search code examples
swiftuidynamicanimatormagnitudeuipushbehavior

How to push dynamic object with same speed using UIPushBehavior?


I'm not a physics expert. However, I want to move UILable which has a dynamic height (depends on content) just like teleprompter. But when I start behaviour with magnitude 10, it starts moving but suddenly its slow down and I want continuous move up at the same speed.

Below is my code :

push = UIPushBehavior(items: [lblText], mode: .instantaneous)
push.setAngle(-.pi/2, magnitude: 10)
animator.addBehavior(push)

lblText size is 375*1500


Solution

  • Josh is right, try adding friction and resistance. To add friction, you will have to create UIDynamicItemBehavior

    let behavior = UIDynamicItemBehavior.init(items: [lblText])
    

    Create this with the items that you need to perform your animations on.

    Then you can add friction and resistance to it

    behavior.friction = 0
    behavior.resistance = 0
    

    And finally add the behavior to the animator

    animator.addBehavior(behavior)
    

    Let me know if this works, happy to help.