Core Animation difficulties with spinning dial control (very detailed)

做~自己de王妃 提交于 2019-12-05 06:42:41

I am remembering there was something about the problem of the animation jumping back into its previous state in the CoreAnimation videos of WWDC10 you can download for free from apple.

I have to look it up later, but there is of course the delegate method - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag which gets called when the animation is done. This would be a nice place to do some housekeeping. Maybe you could there set the y-offset of the layer by looking at the toValue property of the animation.

It is just a long shot, but maybe it is pointing into the right direction.

Olie

Do I understand correctly that the visual effect you want is to have a wheel of numbers (sort of a little like a dartboard) that spin around like the old-style gas/water meter on the side of our house when we were growing up?

If so, why don't you just have a single image that is the digits laid out in a circle, then rotate that one image the desired amount? Something like (untested code typed in browser):

   const double degreesPerDigit = 360.0 / 10.0;
   const double radPerDigit = degreesPerDigit * M_PI / 180.0;
   CGAffineTransform xfm = CGAffineTransformMakeRotation(radPerDigit * digitUp);
   // animated or otherwise:
   myView.transform = xfm;

To your direct questions (again, code typed in browser):

To set a container layer's offset:

CGRect rect = myLayer.frame;
rect.origin.y = newYValue;
myLayer.frame = rect;

To help guard against flicker, there are many techniques, depending on the exact nature of the problem and the desired result, but a common one is to use 2 views that are nearly identical, make changes on view1 then, at the last moment, hide view1 and un-hide view2.

From your questions, it sounds like you have a decent understanding of this stuff, so I'm sorry if I answered below your level, but it's hard to figure out exactly what you're doing and what's going wrong.

Advice: It might be worth your while to both try to carve-back the question to just the important bits and, similarly, to write a stripped-down sample app that does ONLY this animation and nothing else, and then experiment with the minimal test case. Modularize everything, log everything, study the output. Repeat, rinse, fade.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!