Whats the best way to mimic the bouncing animation from the UIAlertView on the iPhone? Is there some built-in mechanism for this? The UIAlertView itself won't work for my needs.
I looked into animation curves but from what I can tell the only ones they provide are easeIn, easeOut, and linear.
UIAlertView uses a more sophisticated animation:
Here's an implementation using a
CAKeyFrameAnimation
:I investigated how animations are added to
UIAlertView
's layer by swizzling-[CALayer addAnimation:forKey:]
. Here are the values I got for the scale transform animations it performs:0.01f -> 1.10f -> 0.90f -> 1.00f
with durations
0.2s, 0.1s, 0.1s
.All the animations use an ease in/ease out timing function. Here is a
CAKeyframeAnimation
that encapsulates this logic:I believe
UIAlertView
also performs a simple opacity animation from0.0f
to1.0f
over the total duration of the transform animation (0.4
).Here's how I did it for an app I'm working on. The effect I was going for was bouncing when you pressed the view. Experiment with the values to suit your taste and the desired speed of the effect.
You can use 2 animations, one to pop up to very large, and the other one to rescale back to normal size.
(This is the approach use by
UIAlertView
internally.)Alternatively, you can use the lower-level
CAAnimation
and use+[CAMediaTimingFunction functionWithControlPoints::::]
to make your own curve.