开发者

Why Core Animation methods are class methods but not instance methods?

In Core Animation framework, why the methods beginAnimations:context: and commitAnimations are class methods of UIView?

Why not being instance methods so we code:

开发者_运维知识库
[widget beginAnimations:@""];
[widget commitAnimations];

instead of:

[UIView beginAnimations:@"" context:widget];
[UIView commitAnimations];


The beginAnimations:context: class method begins an animation "block":

[UIView beginAnimations:@"" context:nil];
view1.frame.x = 10;
view2.opacity = 0.5;
[UIView commitAnimations];

With the above snippet, view1 and view2 will animate the changes inside that block.

The context property is NOT the view you want to animate, just information that can be accessed via the delegate methods.

context

Custom data that you want to associate with this set of animations. information that is passed to the animation delegate messages—the selectors set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

As a sidenote, this way of performing animations is discouraged in iOS4 and above. If you need to target older iOS versions, check the flag:

#if NS_BLOCKS_AVAILABLE
    // iOS4 and above
#else
    // iOS3
#endif
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜