0

I am trying to animate a dot around a rect in a circular fashion. For that I created an oval UIBezierPath, created a CAKeyFrameAnimation and set the path for keyPath 'position'.

I setup a project to experiment with animations and got something working nicely. The problem is, when I add the code to my app, the dot isn't animating. I tried to add that same code to other apps and it work just fine. It doesn't work just for that one app.

The strange thing is that if I replace the path by an array of value containing CGPoint then the dot animates. It's just not working for CGPath for that specific app.

Is there a hidden setting somewhere that blocks CAKeyFrameAnimation using CGPath? Is there another way to do it? Using values it doesn't curve nicely like it does with a path.

Here is the code I used if that helps:

CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path = [self foregroundArcPath].CGPath;
orbit.duration = 0.7f;
orbit.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
[self.foregroundDot addAnimation:orbit forKey:@"orbit"];

Like I said, this code works, just not in this one app. It's my first post here, sorry if it's poorly formulated.

2 Answers 2

0

Perhaps foregroundArcPath is nil or an empty path?

I apologize for giving an answer with little detail. I would have just commented but I am not yet able to do that.

5
  • The path is fine, I verified it many times. I even tried other paths and other layers. Plus that code works when I add it to other projects. It seems like the problem is with that one project. Something must have turned off layer animations around a path, or it's an Apple bug, I really don't know. May 14, 2016 at 11:00
  • That does seem strange, without going through the rest of the code in that project it would be difficult to pin point the problem, or bug if that's the case. The only other thing I could think of to ask is if foregroundDot is a layer that backs a view? Because then you would need to call this inside an animation block for it to work. If it is just a standalone layer then I do not know.
    – dunkmann00
    May 14, 2016 at 15:17
  • foregroundDot is a CAShapeLayer that I added as a subLayer of a view I am displaying on screen. Animating the position of that sublayer should be fine. And as you can see it is called in an animation block anyway. May 14, 2016 at 18:10
  • Gotcha. And my mistake, I was confusing implicit and explicit layer animation. Perhaps you could try to implement '- (void)animationDidStart:' and '- (void)animationDidStop:finished:' just to try and gather more information on whether the animations are even committed and if they are reported as finishing or not.
    – dunkmann00
    May 14, 2016 at 18:34
  • I did that too. Sorry I didn't document everything that I did, but I basically tried everything I could think of. I do receive animationDidStart and didStop messages. I even subclassed UIView and CALayer to debug the added actions for keys. As far as code is concerned it all seems good. I think it's project related, since it only happens in one specific Xcode project. I thought I was missing a setting or something. May 14, 2016 at 20:07
0

I encounter exactly problem as you did. Perhaps your project import some NSObject override class, such as RMMapper.

    -(instancetype)copyWithZone:(NSZone *)zone {
         typeof(self) copiedObj = [[[self class] allocWithZone:zone] init];

CGPath is not suitable for the copy zone.

Hoping this tip will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.