【问题标题】:Start an action with a button when one is already going on当一个动作已经开始时,用一个按钮开始一个动作
【发布时间】:2011-06-20 18:41:42
【问题描述】:
当我单击UIButton,比如b1,会生成两个随机值x 和y,它们成为另一个UIButton 的新坐标,比如b2。 b2 缓慢移动到所需位置(使用 +[UIView animateWithDuration: animations:] )。现在我想要发生的是:当b2 在运动时,再次单击b1 应该将b2 移动到新坐标。现在发生的情况是我无法点击b1,直到b2 很好地位于生成的位置。有什么见解吗?
【问题讨论】:
标签:
objective-c
ios
cocoa-touch
uibutton
core-animation
【解决方案1】:
你会想要使用
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
相反。并在选项中设置UIViewAnimationOptionAllowUserInteraction,这样iOS就不会在动画发生时阻止用户交互。
您还需要设置UIViewAnimationOptionBeginFromCurrentState 以便按钮以当前状态开始。