iOS translation and scale animation iOS translation and scale animation ios ios

iOS translation and scale animation


Why don't you do this...

_menuBtn.transform = CGAffineTransformMakeScale(0.1, 0.1);[UIView animateWithDuration:5.0options:UIViewAnimationOptionCurveEaseOutanimations:^(){    _menuBtn.transform = CGAffineTransformMakeScale(1.0, 1.0);    _menuBtn.center = self.view.center;}completion:nil];

I'd avoid moving stuff using a transform. Change the frame instead.

EDIT

- (void)viewDidLoad{    [super viewDidLoad];}- (void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    // for convenience I'm pulling these values out in to variables.    float buttonWidth = _menuBtn.frame.size.width;    float buttonHeight = _menuBtn.frame.size.height;    float viewWidth = self.view.frame.size.width;    float viewHeight = self.view.frame.size.height;    // set the button frame to be the bottom center    // note you shouldn't have to do this as Interface Builder should already place it there.    // place the button in the horizontal center and 20 points from the bottom of the view.    _menuBtn.frame = CGRectMake((viewWidth - buttonWidth) * 0.5, viewHeight - buttonHeight - 20, buttonWidth, buttonHeight);    // scale the button down before the animation...    _menuBtn.transform = CGAffineTransformMakeScale(0.1, 0.1);    // now animate the view...    [UIView animateWithDuration:5.0                          delay:0.0                        options:UIViewAnimationOptionCurveEaseOut                     animations:^{                         _menuBtn.transform = CGAffineTransformIdentity;                         _menuBtn.frame = CGRectMake(viewWidth - buttonWidth - 20, viewHeight - buttonHeight - 20, buttonWidth, buttonHeight);                     }                     completion:nil];}

Try this and let me know what happens.


This has solved a similar problem.

Apply a (UIButton).imageView Animation.

[UIView beginAnimations:nil context:nil];[UIView setAnimationDelegate:self];[UIView setAnimationDuration:5];[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];CGAffineTransform scaleTrans  = CGAffineTransformMakeScale(1.0f, 1.0f);CGAffineTransform lefttorightTrans  = CGAffineTransformMakeTranslation(-200.0f,0.0f);_menuBtn.imageView.transform = CGAffineTransformConcat(scaleTrans, lefttorightTrans);[UIView commitAnimations];


This phenomenon indicates that your button's original frame is wrong, probably because of its auto-resizing. Try setting its frame to the bottom center before you start the animation.

- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    _menuBtn.superview.frame = CGRectMake(0, 513, 320, 30); // This is a quick and dirty solution to make sure your button's superview is in the right place. You probably don't want to do this and are more likely to review your view hierarchy.    _menuBtn.frame = CGRectMake(145, 0, 30, 30); // Set the frame to the bottom center, please ensure that _menuBtn's transform hasn't been changed before this step    _menuBtn.transform = CGAffineTransformMakeScale(0.1f, 0.1f);    [UIView beginAnimations:nil context:nil];    [UIView setAnimationDelegate:self];    [UIView setAnimationDuration:5];    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];    CGAffineTransform scaleTrans  = CGAffineTransformMakeScale(1.0f, 1.0f);    CGAffineTransform lefttorightTrans  = CGAffineTransformMakeTranslation(-200.0f,0.0f);    _menuBtn.transform = CGAffineTransformConcat(scaleTrans, lefttorightTrans);    [UIView commitAnimations];}