您可以看到我的圆圈的顶部从屏幕底部突出。我的代码非常正常,并且我尝试了多种方法来解决此问题,例如通过在情节提要中创建子视图并将中心设置为父视图,但是没有任何效果。
class ModalViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let Panel = UIView()
Panel.frame = CGRect(x: 0, y: 400, width: 400, height: 200)
Panel.backgroundColor = UIColor.white
view.backgroundColor = UIColor.clear
modalPresentationStyle = .overCurrentContext
view.addSubview(Panel)
let shapeLayer = CAShapeLayer()
let CircularPath = UIBezierPath(ovalIn: Panel.frame)
shapeLayer.path = CircularPath.cgPath
Panel.layer.addSublayer(shapeLayer)
}```
答案 0 :(得分:0)
问题出在
let CircularPath = UIBezierPath(ovalIn: Panel.frame)
由于您要添加一个覆盖Panel
视图的圆圈,因此它应该是
let circularPath = UIBezierPath(ovalIn: panel.bounds)