iosuiviewuikituikit-dynamicsuicollisionbehavior

Problems with UICollisionBehavior


I'm not sure if I've simply found a few bugs in UICollisionBehavior or if I'm just not implementing it correctly.

I am having two main issues.

1) Periodically, I create a UICollisionBehaviors with just two items, a player, and a new item which either falls from the top, or is pushed up from the bottom of the screen.

Every now and then however, two items (which are not the player) will collide with each other. But when I log the collisions in the animator, all of them have just two items, the player and the falling/ascending item.

According to the UICollisionBehavior Class Reference a collision:

You can add multiple collision behaviors to a dynamic animator. A dynamic item can be part of any number of collision behaviors, provided those behaviors belong to the same animator. For example, you can specify a collision behavior for a set of say, blue, items and another for, say, pink items. When you add both behaviors to a dynamic animator, blue items can collide with each other and pink items can collide with each other, but a blue item and a pink item would not collide—they would ignore each other.

Using the above example, my pink items and blue items collide, despite them not being in the same collision behavior.

2) My player is pushed with a UIPushBehavior when the screen is tapped, but every now and then the collisions between the player and an item (falling/ascending) are not caught.

I don't know if the above issues are related so I've put them in the same question for now.

Does anyone have any idea what it could be? Has anyone found this as a bug?

Thanks as ever.


Solution

  • UICollisionBehavior has UICollisionBehaviorMode

    typedef NS_OPTIONS(NSUInteger, UICollisionBehaviorMode) {
        UICollisionBehaviorModeItems        = 1 << 0,
        UICollisionBehaviorModeBoundaries   = 1 << 1,
        UICollisionBehaviorModeEverything   = NSUIntegerMax
    } NS_ENUM_AVAILABLE_IOS(7_0);
    

    the default is UICollisionBehaviorModeEverything so the items will collide with boundaries and with other items. You need to set this property to UICollisionBehaviorModeBoundaries