KexAri KexAri - 3 months ago 21
Objective-C Question

How do I create a bouncing popover animation like this?

I want to create an animated popover bubble like the one below. With the same expanding/contracting bounce animation. Does anyone know how to go about this? Is is just a UIView with animation? What animation effect is this? Any pointers on how to go about this would be really appreciated. Thanks!

enter image description here

Answer

You can use the

Obj-C:

animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:animations completion: method like this:

UIView *animationView = [[UIView alloc] initWithFrame:CGRectMake(50, 90, 100, 50)];
animationView.backgroundColor = [UIColor redColor];
animationView.transform = CGAffineTransformMakeScale(0, 0);
[self.view addSubview:animationView];

[UIView animateWithDuration:0.3
                      delay:0
     usingSpringWithDamping:0.5
      initialSpringVelocity:5
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     animationView.transform = CGAffineTransformIdentity;
                 }
                 completion:nil];

Swift:

var animationView: UIView = UIView(frame: CGRectMake(50, 90, 100, 50))
animationView.backgroundColor = UIColor.redColor()
animationView.transform = CGAffineTransformMakeScale(0, 0)
self.view!.addSubview(animationView)
UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: .CurveEaseInOut, animations: {() -> Void in
    animationView.transform = CGAffineTransformIdentity
}, completion: { _ in })

enter image description here

Comments