I am trying to animate a UIlabel to first grow larger, then shrink back to its original frame. Enlarging work as expected, but not shrinking. When I shrink the label with the below code, the size adjusts first before the origin is shifted. This causes a two step animation which isn't smooth.
Here is my code:
CGRect rect = label.frame;
[UIView animateWithDuration:.2
delay: 0.1
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
label.frame = CGRectMake(rect.origin.x + 4,
rect.origin.y + 4,
rect.size.width-8,
rect.size.height-8);
}
completion:^(BOOL finished){
}];
You could try applying a transform to the label inside your animation block instead of adjusting the rect. Something like the following lines for the grow/shrink animations:
label.transform = CGAffineTransformMakeScale(1.5, 1.5); //grow
label.transform = CGAffineTransformMakeScale(1, 1); //shrink
Please tryout this solution, I guess it is what you are looking for. I have tested it for working but please try and let me know if you are looking for this or not.
-(IBAction)growanimate:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(shrinkanimate)];
label.transform = CGAffineTransformMakeScale(2.0f, 2.0f); //This will double label from current size.
[UIView commitAnimations];
}
-(void)shrinkanimate
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
label.transform = CGAffineTransformMakeScale(1.0f, 1.0f); //This will get it back to original size.
[UIView commitAnimations];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With