UIBezierPath Triangle反向

时间:2017-09-02 21:12:48

标签: ios swift uibezierpath

目前我遇到一个小问题。下面的代码将在tableViewHeader的顶部输出一个三角形图层,但我想要反转bazier路径的切割方向。

代码:

let cutDirection = UIBezierPath()
cutDirection.move(to: CGPoint(x: 0, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height))
cutDirection.addLine(to: CGPoint(x: 0, y: headerRect.height - headerCut))
newHeaderLayer.path = cutDirection.cgPath

输出:

enter image description here

enter image description here

结果我正在寻找:

感谢您的帮助!

凯文。

3 个答案:

答案 0 :(得分:0)

试试这个:

let cutDirection = UIBezierPath()
cutDirection.move(to: CGPoint(x: 0, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height - headerCut))
cutDirection.addLine(to: CGPoint(x: 0, y: headerRect.height))
newHeaderLayer.path = cutDirection.cgPath

答案 1 :(得分:0)

如果我正确地遵循了这一点,你应该交换以下内容:

h1 span{
   position:absolute;
}

要:

cutDirection.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height))
cutDirection.addLine(to: CGPoint(x: 0, y: headerRect.height - headerCut))

答案 2 :(得分:0)

通过旧学校的方式修复它:在纸上!

<强>解决方案:

let cutDirection = UIBezierPath()
cutDirection.move(to: CGPoint(x: 0, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height - headerCut))
cutDirection.addLine(to: CGPoint(x: 0, y: headerRect.height))
cutDirection.close()
newHeaderLayer.path = cutDirection.cgPath