gpt4 book ai didi

ios - 仅在 View 顶部添加圆角

转载 作者:行者123 更新时间:2023-11-28 08:10:26 24 4
gpt4 key购买 nike

我正在尝试实现这样的 View : enter image description here

我一直在尝试使用这段代码让 maskPath = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: [.topRight, .topLeft], cornerRadii: CGSize(width: 140, height: 140))

但我得到的只是这样的:

enter image description here

我已经尝试更改 widthheight 值,但 View 似乎根本没有改变,那么我该如何绘制一个包含圆形的 View 顶部如第一张图片所示?

感谢您提出解决方案,但正如我上面所说,我可以将角设置为圆角,我不能只将 View 的顶部设为圆形,所以这是一个不同的问题。

最佳答案

您可以尝试使用 a circular UIBezierPath并调整其半径。这样,只要您的 View 不会无限期地扩展(就像 UIScrollView 那样),您就会获得想要的效果。

let radiusRatio = CGFloat(2 / 3)

let screenRect = UIScreen.main.bounds
let screenHeight = screenRect.height
let screenWidth = screenRect.width
let circleCenter = CGPoint(x: screenWidth / 2, y: screenHeight / ((1/radiusRatio) * 2))

let maskPath = UIBezierPath(arcCenter: circleCenter,
radius: screenHeight * radiusRatio,
startAngle: 0,
endAngle: CGFloat.pi,
clockwise: true)

radiusRatio 变量控制圆的半径占屏幕高度的多少,或者换句话说,圆的中心有多低。调整 radiusRatio 应该最终会给你你想要的。

关于ios - 仅在 View 顶部添加圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43922267/

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