简体   繁体   中英

uiview CGAffineTransform animates backwards

I have a UIView subclass which I am able to successfully use UIView animations on.

This UIView also has subviews, which I also want to be able to UIView animate.

However, it seems that whenever I create an animation and apply it to the parent view it works fine, but if I apply the animation to the child view it animates backwards.

For example, if I scale my UIView parent(self) by a factor of 2 (to double the width and height):

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration:2];
[UIView setAnimationDelay:2];

CGAffineTransform scaleTransform = CGAffineTransformScale( self.transform, 2, 2  );
self.transform = scaleTransform;
[UIView commitAnimations];

then this works fine.

But if I do the same on the child:

UIView *myObj = [[self subviews] objectAtIndex:0];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration:2];
[UIView setAnimationDelay:2];

CGAffineTransform scaleTransform = CGAffineTransformScale( myObj.transform, 2, 2  );
myObj.transform = scaleTransform;
[UIView commitAnimations];

It doesn't work. What happens visually is that the child view immediately shrinks down and then after the delay scales back up to it's original size.

If I log the transform parameters it looks the same for both parent and child and I have tried setting CGAffineTransformIdentity .

Any ideas what might be the problem?

I was overriding layoutSubviews and in there I was assigning sizes/positions of the views based upon device orientation which was conflicting.doh!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM