Change bounds of UIView and have UICollisionBehavi

2019-03-31 12:04发布

问题:

Is it possible to change the bounds of a UIView (which is attached to some other UIViews using UIAttachmentBehaviors) and have the UICollisionBehavior in combination with the UIAttachmentBehavior respond to it (like the sample movie here: http://www.netwalkapps.com/ani.mov, whereby upon touch the ball UIView grows and the other ball UIViews move out of the way)?

Thanks! Tom.

回答1:

I got this to work but it was pretty hacky. I had to remove all behaviors from my animator object and re-add them again.

- (void)_tickleBehaviors
{
    NSArray *behaviors = [self.animator.behaviors copy];
    for (UIDynamicBehavior *behavior in self.animator.behaviors) {
        [self.animator removeBehavior:behavior];
    }

    for (UIDynamicBehavior *behavior in behaviors) {
        [self.animator addBehavior:behavior];
    }
}