【发布时间】:2020-06-01 09:06:09
【问题描述】:
我想驱动一条平滑的曲线,曲线的 1/3 向外,2/3 向内。这就是我想要实现的目标。
到目前为止,我尝试添加 1 条曲线,例如:
var height: CGFloat = UIScreen.main.bounds.height / 14
let centerWidth = self.frame.width / 2
let screenView = UIScreen.main.bounds
let width = (screenView.width - (2*screenView.width/40)) / 10
path.move(to: CGPoint(x: 0, y: 0)) // start top left
path.addLine(to: CGPoint(x: (centerWidth - width * 2.5), y: 0)) // the beginning of the trough
// first curve down
path.addCurve(to: CGPoint(x: centerWidth , y: height),
controlPoint1: CGPoint(x: (centerWidth - width * 1.33), y: 0), controlPoint2: CGPoint(x: centerWidth - width * 1.33 , y: height))
但是当我尝试这条向外和向内的曲线时,它们的高度相同。所以我改变了它并尝试添加2条曲线:
path.move(to: CGPoint(x: 0, y: 0)) // start top left
path.addLine(to: CGPoint(x: (centerWidth - width * 2.5), y: 0)) // the beginning of the trough
// first curve down
path.addCurve(to: CGPoint(x: centerWidth - width * 1.33 , y: height/3),
controlPoint1: CGPoint(x: (centerWidth - width * 1.33), y: 0), controlPoint2: CGPoint(x: centerWidth - width * 1.33 , y: height/3))
path.addCurve(to: CGPoint(x: centerWidth, y: height),
controlPoint1: CGPoint(x: centerWidth - width * 1.33 , y: height/3), controlPoint2: CGPoint(x: centerWidth - width , y: height ))
我尝试了很多东西,但无法准确地画出我想要的东西。那么我怎样才能绘制一条端点高度的 1/3 向外和 2/3 向内看起来像一个整体的曲线。
我对各种想法持开放态度。问候
注意
我正在尝试自定义tabbar 的中心按钮,其高度值为UIScreen.main.bounds.height,宽度为`
let screenView = UIScreen.main.bounds
let width = (screenView.width - (2*screenView.width/40))`
【问题讨论】:
-
顺便说一句,我建议不要在自己的绘图代码中使用
UIScreen.main.bounds。它使它变得非常脆弱,如果它曾经在分屏多任务环境中使用,比如 iPad,就会失败。始终只引用视图的bounds,而不是屏幕尺寸。
标签: ios swift uibezierpath curve