1

I created a UIImageView that has a custom shadowPath. This view will be moved left and right across the screen, but I need the shadowPath to have a different transformation than the image layer itself. Is this possible? Moving the image itself works, and the shadow moves as well when I do the following:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
im.center = location;
[UIView commitAnimations];

But if I try to add a layer transformation before "commitAnimations", the shadow will simply take on that property right away, for example:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
im.center = location;
im.layer.shadowPath = [self createPerspectiveShadow:im]; //this will not animate
[UIView commitAnimations];

So, my question is, is there a way to recalculate a shadow during the animation?

Thanks

Mirkules
  • 1,709
  • 15
  • 21

2 Answers2

2

The UIView animations don’t always allow you to animate CALayer attributes; try using a CABasicAnimation instead.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
  • Unfortunately, a CABasicAnimation probably won't cut it because I have to recalculate the entire shadow path. CABasicAnimation.fromValue and .toValue require NSNumbers, and I can't pass a CGPathRef to them instead. Is there something I'm missing? – Mirkules Mar 04 '11 at 01:02
  • 1
    Hmm, that’s a tough one. You may be better off setting up an `NSTimer` to fire once every 1/60th of a second, then updating the position of the shadow programmatically. Sucks, but it’ll work… – Jeff Kelley Mar 04 '11 at 01:30
  • I was afraid this was going to come up :) Oh well, I was hoping for a quicker, easier solution. Anyway, thanks for your input Jeff (I'll mark your answer in a day or two...) – Mirkules Mar 04 '11 at 04:55
  • A bit late but you can definitely animate paths with CABasicAnimation. `fromValue` and `toValue` are `id`, so just do a `(__bridge id)` on the `CGPathRef`. – fumoboy007 Dec 30 '13 at 07:11
1

You can pass a CGPathREf to the toValue

theAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:newRect].CGPath;

see this post

Community
  • 1
  • 1
Gering
  • 3,010
  • 3
  • 21
  • 23