Some consultants built some code for us. I’m looking at a method they wrote for UIView subclass. It basically goes like this:
- (void)startAnimation {
[self.circle removeAllAnimations];
// then some animation code for the circle. The circle is a CAShapeLayer.
[self.circle addAnimation:group forKey:@"animationPath"];
}
Two questions, is this a good way to implement animations? Like remove all animations first, then add it? I was wondering if this is an expensive operation to always remove the animations first because in another for loop somewhere else in the app, it basically looks at the objects and just calls:
for (id points in pointsArray) {
[points startAnimation];
}
I was wondering if blindly removing the animations and adding them back, without checking to see if the point object was already animating is ok and if I’d be taking a performance hit.
Also, is there a way to check something is animating? Looking at the code, the animation starts for all objects. However if they are positioned off the screen, (because it’s in a scrollView and it’s not currently in view), the objects do not animate even though startAnimation is called on each object when they are created and added to the view. Thanks.
Personally, I dont think is a bad way of working, getting sure you remove every animation that could be running in that moment before you add yours, but as I said, this is a personal opinion.
I dont think is going to be a really bad performance hit, specially taking into account that probably in that moment, no animation is running, but as I said, this is just personal.
On the other hand, if you check apple developers guide, it seems that it doenst remove the animations
https://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html