fade in an bounce animation subview

532 Views Asked by At

I have an subview that fades into the view. this goes perfectly with this code:

UIView.animateWithDuration(0.9,  animations: {
            self.popUpView.backgroundColor = UIColor.blackColor()

})

But how can i make a sort of bounce? That the popupview fades in very hard and bounces a little bit back.

1

There are 1 best solutions below

0
On BEST ANSWER

From UIView, you could use:

class func animateWithDuration(_ duration: NSTimeInterval,
                         delay delay: NSTimeInterval,
        usingSpringWithDamping dampingRatio: CGFloat,
         initialSpringVelocity velocity: CGFloat,
                       options options: UIViewAnimationOptions,
                    animations animations: () -> Void,
                    completion completion: ((Bool) -> Void)?)

To change the bounciness you'll want to change the dampingRatio; zero being the most bouncy and one being the least bouncy. From the UIView documentation:

Damping Ratio: The damping ratio for the spring animation as it approaches its quiescent state.

To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation.