Swift UIKit Dynamics add collision boundary. After rotation does not work correctly

93 views Asked by At

I have set some UIKit Dynamics boundaries for UIBezierPath of several UIImageView objects.

block1path = UIBezierPath(rect: block1.frame)
collision.addBoundary(withIdentifier: "block1" as NSCopying, for: block1path)

However when I rotate the UIImageView using a slider

        selectedValue = Float(sender.value)
        
        if slectedObject == "bouncer2" {
            bouncer2.transform = CGAffineTransform(rotationAngle: CGFloat(selectedValue))}
        
        if slectedObject == "block1" {
            block1.transform = CGAffineTransform(rotationAngle: CGFloat(selectedValue))
            }

The collision boundary appears to still maintain the horizontal frame rather than the rotated one. So other objects hit what appear to be empty spaces. I have tried to remove the boundary and add again after rotation and also used updateItemUsingCurrentState to refresh the UIDynamicAnimator for that item but so far nothing is working.

Interestingly It does seem to work if the image is rotated 90 / 180 or 270 deg. But does not work for non horizontal or vertical rotations?

0

There are 0 answers