animateWithDuration:animations:completion:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值