animateWithDuration:animations:completion:
為什么80%的碼農都做不了架構師?>>> ??
Creates an animation block object that can be used to set up keyframe-based animations for the current view.
Declaration
(void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Parameters
duration
The duration of the overall animation, measured in seconds. If you specify a negative value or 0, changes are made immediately and without animations.
delay
Specifies the time (in seconds) to wait before starting the animation.
options
A mask of options indicating how you want to perform the animations. For a list of valid constants, see “UIViewKeyframeAnimationOptions”.
animations
A block object containing the changes to commit to the views. Typically, you call the addKeyframeWithRelativeStartTime:relativeDuration:animations: method one or more times from inside this block. You may also change view values directly if you want those changes to animate over the full duration. This block takes no parameters and has no return value. Do not use a nil value for this parameter.
completion
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. You can use a nil value for this parameter.
我一直不明白最后的completion什么用,參考中的回答者大概回答了。
意思是說你可以當你中斷或者取消了一個動畫,里面的completion會為FALSE。你要清楚,雖然取消了這個動畫,但是completion block回調函數仍然會執行。如果你連接了動畫序列,你想讓這個序列停止的話,你只需要繼續之前已經完成的動畫。
如果你寫一個游戲,預期是炸彈從屏幕飛過。那么你有一個動畫來讓炸彈移動,你的completion block寫的是另外一個動畫來展示炸彈爆炸,然后下面你可能調用一些方法來減分或者其他。
如果玩家點擊了炸彈,你應該取消炸彈的移動動畫,然后炸彈安然無恙的飛過。你之前的completion仍然會執行,所以你應該知道動畫已經被執行結束或者被取消。
參考:http://stackoverflow.com/questions/8686922/what-exactly-does-bool-parameter-do-in-animatewithdurationanimationscompletion
轉載于:https://my.oschina.net/itfanr/blog/372903
總結
以上是生活随笔為你收集整理的animateWithDuration:animations:completion:的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android HOME键的监听
- 下一篇: python安装pyopenssl