I am trying to work on an iOS iPhone app that uses UIKit Dynamics in order to do the physics animation. It's a basketball game where you can throw the ball into the hoop. However, I can't figure out how to make the ball circular (treated this way by the UICollisionBehavior
and UIDynamicAnimator
)?
I've tried: ball.layer.cornerRadius = ball.frame.size.width / 2.0;
But this only draws the ball circular. It doesn't actually behave this way. I also know I can draw boundaries using: addBoundaryWithIdentifier:forPath:
But I can't figure out how to put bounds around a UIView
(UIImageView
in my case) that aren't just a rectangle? I know I could do this using SpriteKit, but I've already written a few hours of code for the basketball game using UIKit Dynamics and don't want to switch over if there is a simple fix. Thank you!
In
iOS 9
you can now do exactly what you want.In your
UIView
subclass you can add this: