0

I want to clip the bounds of my UIView perfectly to interact as a circle, but however I set the corner radius, mask and clip to bounds and it shows correctly, it moves as a square, as you can see in the image: enter image description here

The code I have used is:

let bubble1 = UIView(frame: CGRectMake(location.x, location.y, 128, 128))
bubble1.backgroundColor = color2
bubble1.layer.cornerRadius = bubble1.frame.size.width/2
bubble1.clipsToBounds = true
bubble1.layer.masksToBounds = true

What is wrong there that does still keeping the edges of the view?

PD: All the views moves dynamically, so when it moves and hit each other, it shows these empty space, acting as an square instead of as an circle

Sergio
  • 82
  • 7
  • what's the problem? what do you mean by "it moves as a square"? – Ozgur Vatansever Apr 24 '16 at 08:59
  • @ozgur The view is animated, and when it moves, it does not hit the other views, as you see in the image there is an empty space, which i think is the edges of the original square view. What I mean as a square is that it collapses as an square instead of as a circle, leaving these horrible empty space between each other. – Sergio Apr 24 '16 at 09:00
  • did you try manually intersecting them by changing their frames so that you could see any white corners thoroughly? – Ozgur Vatansever Apr 24 '16 at 09:02
  • @ozgur I set them with a method, but I set manually the x y position. However I have tried manually and it still showing these empty space between – Sergio Apr 24 '16 at 09:04
  • Consider using Spritekit? – Hack Saw Apr 24 '16 at 09:06
  • @HackSaw I'm using UIDynamics so I'd like to keep my uiview in order to not have to change all code, or is much more easier using sprite? – Sergio Apr 24 '16 at 10:01
  • may be this may help in making the selection:http://stackoverflow.com/a/23347609/4557505 – HardikDG Apr 24 '16 at 10:57
  • @Pyro Thank you for your reply, this is exactly what It's happening here. Do you recommend me use sprite kit? My UIDynamics function is working as I want, the only problem is the rounded, and I have no idea of sprite kit :/ – Sergio Apr 24 '16 at 12:24
  • It may depend on your code,to be honest, I didn't use Sprite kit, so don't know how many changes you have to make or it can solve your requirement properly – HardikDG Apr 24 '16 at 12:33

1 Answers1

1

Finally, after all I found what to implement, and was just that class instead of UIView:

class SphereView: UIView {
    // iOS 9 specific
    override var collisionBoundsType: UIDynamicItemCollisionBoundsType {
        return .Ellipse
    }
}

Seen here: https://objectcoder.com/2016/02/29/variation-on-dropit-demo-from-lecture-12-dynamic-animation-cs193p-stanford-university/

Sergio
  • 82
  • 7