Sergio
Sergio

Reputation: 82

CornerRadius exactly UIView

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

Upvotes: 0

Views: 550

Answers (1)

Sergio
Sergio

Reputation: 82

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/

Upvotes: 1

Related Questions