Reputation: 849
I try to implement simple animation to change view position I use this code:
[UIView animateWithDuration:0.4 animations: ^{
self.greenIm.frame = CGRectMake(self.roundView.frame.origin.x, self.roundView.frame.origin.y - 110, 60, 60);
self.greenIm.layer.cornerRadius = self.greenIm.frame.size.height / 2;
}
But what I see, my rounded view self.greenIm go to new position without rounding and only at the end stay rounded, looks bad.
Later I want change size of another View but I need same center:
[UIView animateWithDuration:0.4 animations: ^{
self.cup.frame = CGRectMake(self.cup.frame.origin.x, self.cupImage.frame.origin.y, self.cup.frame.size.width - 20, self.cup.frame.size.height - 20);
self.cup.center = self.centerPoint;
}
Here I see same, first view change size later centering.
How fix it ? How I understand UIView animation anime all properties not in one time. Please help.
Upvotes: 0
Views: 1238
Reputation: 2417
For you first problem, Apple documentation says that you can animate the properties, which are animatable.
A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.
If you see the documentation for UIView properties, you will find that layer is not animatable. You need to use Core Animation to achieve this. Use the below code. I am using a UILabel for this sample code. See if this helps.
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
[anim setFromValue:[NSValue valueWithNonretainedObject:[NSNumber numberWithDouble:10.0]]];
lblView.layer.cornerRadius = 30.0;
[anim setDuration:6];
[lblView.layer addAnimation:anim forKey:@"move"];
In this very same fashion you can create another animation object for position property and change the frame as desired. Add that animation to layer and both animation will start in parallel.
Upvotes: 1