gpt4 book ai didi

swift - CornerRadius 恰好是 UIView

转载 作者:行者123 更新时间:2023-11-30 10:04:32 24 4
gpt4 key购买 nike

我想完美地剪辑 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

仍然保留 View 边缘有什么问题吗?

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

最佳答案

最后,毕竟我找到了要实现的内容,而且只是那个类而不是 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/

关于swift - CornerRadius 恰好是 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36821110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com