Perfect swift3 boing

Panel Opening Animation ...

@IBOutlet var barHeight: NSLayoutConstraint!


    barHeight.constant = barShut?30:100
    self.view.layoutIfNeeded()
    t = !barShut?30:100

    UIView.animate(withDuration: 0.15,
        delay: 0,
        options: UIViewAnimationOptions.curveEaseOut,

        animations: { () -> Void in
            self.barHeight.constant = t
            self.view.layoutIfNeeded()
        },

        completion: {_ in
            Screen.barShut = !Screen.barShut
        }
    ) 

It's great...

enter image description here

But how would you do that?

enter image description here

(The only way I would like to do this is to use CADisplayLink with a few lines of code for a decaying spring.) Is this available in UIKit?

+4
source share
1 answer

You can use the spring animation method that is built into the UIView:

func toggleBar() -> Void {
    self.view.layoutIfNeeded()
    let newHeight:CGFloat = !barShut ? 30:100
    barShut = !barShut

    barHeightConstraint.constant = newHeight

    UIView.animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 3, options: [], animations: {
        self.view.layoutIfNeeded()
    }, completion: nil)

}

You will need a longer animation duration than 0.15 seconds to make the rebound seem realistic; I think the values ​​that I look pretty good, but you can play with them to get the exact effect that you are after.

, , , /, . barShut , . , .

+1

Source: https://habr.com/ru/post/1672568/


All Articles