开发者

How to check if a NSProgressIndicator is currently animated?

NSProgressIndicator has methods called startAnimation: and stopAnimation:, but no method that I can find to check the state (whethe开发者_运维知识库r it is currently animating or not). How would you do it?


You should not be storing the state of a control in the control itself.

The progress indicator control doesn't provide access to its animated state because unlike something like a text field, the user can't change the state of the control. You will never be in a situation where the state of the control changes without your code initiating it. Because you are the one who sets the state of it, so you should keep track of it.

Cocoa uses the Model-View-Controller pattern and a progress indicator is a view. If you store state in the control then you are violating the MVC pattern.

Your View should reflect your Model at all times, and the Controller is there to ensure the view and model are kept in sync.

You should either use Cocoa Bindings to bind the animated state of your progress indicator to a BOOL stored in your model (preferred) or implement code in your controller class to control the animated state of the progress indicator when there is a change to a BOOL stored in your model.


You could just keep a BOOL value somewhere in your class that you set to YES or NO when you start and stop the animation respectively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜