Apple Dev文档吐槽

最近在看CALayer相关知识的时候读到了当修改UIView的layer的property的时候,并不会产生动画的情况的问题(不在animation block里的情况下),然后看到很多人解释说是由于UIView在它的actionForLayer:forKey:方法中返回了一个NSNull object,从而阻止了CALayer继续搜索action。而经过反复查看CALayer的actionForKey:这个方法的解释,我发现文档里并没有说为返回NSNull后actionForKey:方法就会停止搜索。在文档中关于返回NSNull的情况的描述只有这么一段话:

If any of the above steps returns an instance of NSNull, it is converted to nil before continuing.

这段话跟本就没说如果返回NSNull就会停止搜索,那这是怎么回事呢??事实上,这只是因为文档说的不完整而已,更完整的描述可在CALayer.h文件中找到,在CALayer头文件里关于actionForKey:这个方法的描述中有这么一段话:

If any of these steps results in a non-nil action object, the following steps are ignored. If the final result is an instance of NSNull, it is converted to `nil'

看完这句话,我才明白,由于[NSNull null]是一个non-nil object,所以才会让actionForKey:方法停止搜索,而之后这个NSNull object才又会被转换成nil,这样就达到了又停止了搜索,又不返回任何action的目的。因此,在这里我真的想吐槽一下Apple的Dev文档,为啥说明就不能再写的全一点呢,想单独靠读文档进行开发,真的很麻烦。。

最后附上CALayer.h中对actionForKey:这个方法搜寻action的完整说明:

Returns the action object associated with the event named by the string 'event'. The default implementation searches for an action object in the following places:
1. if defined, call the delegate method -actionForLayer:forKey:
2. look in the layer's actions' dictionary 3. look in any 'actions' dictionaries in the 'style' hierarchy 4. call +defaultActionForKey: on the layer's class **If any of these steps results in a non-nil action object, the following steps are ignored. If the final result is an instance of NSNull, it is converted tonil'.**

你可能感兴趣的:(Apple Dev文档吐槽)