0

I am working with UIDynamicAnimator, UICollisionBehavior and several moving UIImageView. It looks like this when everything is working fine. Pictures are moving on the screen without superposition. Moving views with good collision

But after I changed the bounds of some views, the collision doesn't update as it should and it gives me this: Moving views after bounds animation

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?

Tulleb
  • 8,919
  • 8
  • 27
  • 55

2 Answers2

0

I succeed to do it by setting my animator variable to nil and declaring it and every linked animation behaviors again.

If someone else has a better way to do it, I am still listening. Thanks.

Tulleb
  • 8,919
  • 8
  • 27
  • 55
0

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)
        }
Thomas LEVY
  • 310
  • 3
  • 5
  • I think I already tried that but didn't work out... I'll try again asap and give you feedback. Thanks. – Tulleb Apr 07 '16 at 15:36