视图边界发生变化时发生碰撞

Collision when bounds of a view are changing

我正在使用 UIDynamicAnimator、UICollisionBehavior 和几个移动的 UIImageView。 一切正常时看起来像这样。图片在屏幕上移动,没有叠加。

但是在我更改了一些视图的边界之后,碰撞并没有像它应该的那样更新,它给了我这个:

碰撞不再像预期的那样起作用:视图重叠。

我正在用这段代码更新边界:

    [UIView animateWithDuration:2
                      delay:0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     CGRect newBounds = imageView.bounds;
                     newBounds.size.height = 500;
                     newBounds.size.width = 500;
                     imageView.bounds = newBounds;
                 }
                 completion:^(BOOL finished) {
                     [animator updateItemUsingCurrentState:imageView];
                 }];

updateItemUsingCurrentState: 函数似乎对边界变化没有影响...我说得对吗?

我通过将我的动画变量设置为 nil 并再次声明它和每个链接的动画行为来成功做到这一点。

如果其他人有更好的方法,我还在听。谢谢。

我最终从动态动画师中删除了所有行为,但没有解除分配并再次重新添加它们:

        let behaviors = (self.dynamicAnimator.behaviors as NSArray).copy() as! [UIDynamicBehavior]
        self.dynamicAnimator.removeAllBehaviors()
        for behavior in behaviors {
            self.dynamicAnimator.addBehavior(behavior)
        }