CornerRadius完全是UIView

时间:2016-04-24 08:58:01

标签: swift uiview rounded-corners

我想完美地剪切我的UIView的边界以作为圆形进行交互,但是我将角半径,蒙版和剪辑设置为边界并且它正确显示,它移动为正方形,如图所示:enter image description here

我使用的代码是:

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

那仍然保持视图边缘的错误是什么?

PD:所有视图都是动态移动的,所以当它移动并相互碰撞时,它会显示这些空白空间,充当方形而不是圆形

1 个答案:

答案 0 :(得分:1)

最后,毕竟我找到了要实现的内容,而且只是那个类而不是UIView:

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

见到这里:https://objectcoder.com/2016/02/29/variation-on-dropit-demo-from-lecture-12-dynamic-animation-cs193p-stanford-university/