0

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?

Guitarman4
  • 33
  • 5
  • 1
    If your boundary is the frame of the view, why bother adding boundaries manually, at all? E.g. `let collision = UICollisionBehavior(items: [animatedView, fixedView])` and then you automatically have boundaries on the frames of the views and it honors the rotation, e.g. https://i.stack.imgur.com/j4nhi.gif – Rob Apr 21 '22 at 03:38
  • 1
    Generated via https://gist.github.com/robertmryan/98e5f842f73800e88001f1b41585b50a... – Rob Apr 21 '22 at 03:54
  • Thanks. I only want part of the top edge of the bouncer to have a push effect on collision. Your solution will work well for a simple boundary. So if the moving object hits the bottom that will work well, but when it hits the top I want it to bounce high. ( like pinball machine ) But this also needs to be at the rotational direction of the bouncer. Could I somehow use the p: (CGPoint) in func collisionBehavior to specify the top edge of bouncer? Also how do you identify the bouncer collision? @Rob – Guitarman4 Apr 21 '22 at 09:09

0 Answers0