简体   繁体   English

视图范围发生变化时发生碰撞

[英]Collision when bounds of a view are changing

I am working with UIDynamicAnimator, UICollisionBehavior and several moving UIImageView. 我正在使用UIDynamicAnimator,UICollisionBehavior和几个移动的UIImageView。 It looks like this when everything is working fine. 当一切正常时,看起来像这样。 Pictures are moving on the screen without superposition. 图片在屏幕上移动时没有重叠。 碰撞时移动视图

But after I changed the bounds of some views, the collision doesn't update as it should and it gives me this: 但是,当我更改了某些视图的边界后,碰撞并没有按应有的方式更新,这给了我: 边界动画后移动视图

The collision doesn't work anymore as expected: views became superposed. 碰撞不再按预期工作:视图被叠加。

I am updating the bounds with this code: 我正在用以下代码更新界限:

    [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: function doesn't seem to have effect on bounds changes... Am I right? updateItemUsingCurrentState:函数似乎对边界更改没有影响...对吗?

I succeed to do it by setting my animator variable to nil and declaring it and every linked animation behaviors again. 通过将动画变量设置为nil并再次声明它以及每个链接的动画行为,我成功地做到了。

If someone else has a better way to do it, I am still listening. 如果还有其他更好的方法,我仍在听。 Thanks. 谢谢。

I ended up removing all behaviors from the dynamic animator without deallocing it and re-adding them again: 我最终从动态动画师中删除了所有行为,而没有取消分配它并再次重新添加它们:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM