UIButton AppStore Button Animation

You have sample code for animating the UIButton AppStore Price → to Buy button. I tried a lot, but with CAAnimationGroup (scaling + translation) this does not work well and it does not work, just setting it to the new frame size in the UIView beginAnimations. The animation first sets a new width (right away) and then a new beginning .. so this is not the right effect ...

Thanks!

+6
iphone core-animation
source share
2 answers

Do you make your changes inside the Core Animation block?

I created a simple iPhone based application to test this. The view has two rounded rectangular UIButton objects:

  • The first button is in the upper right corner with a width of 62 (and a height of 35) and the initial name is "$ 0.99". It is connected to the "button" connector and "animate" the action in the view controller. This is the button that will be animated when it is clicked.

  • The second button is located at the bottom of the screen with the name "Reset" and is connected to the "Reset" action in my view controller.

Here is the view controller code:

UIButtonAnimationTestViewController.h:

#import <UIKit/UIKit.h> @interface UIButtonAnimationTestViewController : UIViewController { IBOutlet UIButton *button; CGRect originalFrame; } - (IBAction)animate; - (IBAction)reset; @end 

UIButtonAnimationTestViewController.m:

 #import "UIButtonAnimationTestViewController.h" @implementation UIButtonAnimationTestViewController - (void)viewDidLoad { [super viewDidLoad]; originalFrame = button.frame; } - (IBAction)animate { CGRect frame = button.frame; frame.origin.x -= 30; frame.size.width += 30; [UIView beginAnimations:@"button" context:nil]; button.frame = frame; [button setTitle:@"" forState:UIControlStateNormal]; [UIView setAnimationDelegate:self]; [UIView commitAnimations]; } - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [button setTitle:@"BUY NOW" forState:UIControlStateNormal]; } - (IBAction)reset { button.frame = originalFrame; [button setTitle:@"$0.99" forState:UIControlStateNormal]; } 
+5
source share

There is a problem with this when you use a background with three parts of the image for UIButton: http://openradar.appspot.com/7290242

The button will appear on the right first, and then move it to the left. This approach will not work

+1
source share

All Articles