Question

I've got a view with a button that moves up when it's tapped via simple translation. However, the UIButton also seems to move downward a few points when using a CGAffineTransformTranslate. How can I remedy this animation?

- (IBAction)moveButton:(id)sender {
    UIButton *button = (UIButton *)sender;

    [UIView animateWithDuration:2.4f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{

                         button.transform = CGAffineTransformTranslate(button.transform, 0, -49);
                     }
                     completion:^(BOOL finished){}
     ];

}

how it looks at the moment

Was it helpful?

Solution

Your code works fine; the problem has to be elsewhere.

Make sure that you're not doing any layout work somewhere else that interferes with your translation. If you have set up Autolayout constraints for your button, this could cause the behavior you're seeing. You could disable Autolayout for this UIView in the File Inspector (at least temporarily) to find out if that's the case.

You might want to consider changing the button's frame instead of applying a transformation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top