ios - 在 iOS 中以波形切割 View

标签 ios uiview swift4 uibezierpath xcode9.4

我正在尝试以编程方式创建如下所示的 View 。我相信我需要使用 Beizer 路径,但不确定我应该如何处理路径点?感谢任何帮助

enter image description here

func createShape() -> UIBezierPath {

    // create a new path
    let path = UIBezierPath()

   //Need to determine path points here
}

最佳答案

你需要什么样的形状请引用下面的代码,希望对你有帮助

 let view = UIView(frame: CGRect(x: 50, y: 100, width: 200, height: 300))

        let path = UIBezierPath()
        path.move(to: CGPoint(x: 0.0, y: 200))
        path.addCurve(to: CGPoint(x: 200, y:150),
                      controlPoint1: CGPoint(x: 50, y: 350),
                      controlPoint2: CGPoint(x:150, y: 0))
        path.addLine(to: CGPoint(x: view.frame.size.width, y: view.frame.size.height))
        path.addLine(to: CGPoint(x: 0.0, y: view.frame.size.height))
        path.close()

        let shapeLayer = CAShapeLayer()
        shapeLayer.path = path.cgPath

        view.backgroundColor = UIColor.black
        view.layer.mask = shapeLayer
        self.view.addSubview(view)

这是我的输出 enter image description here

关于ios - 在 iOS 中以波形切割 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52035801/

相关文章:

ios - Objective-C - 获取本地化的周末和工作日名称?

ios - UIViewController 旋转 View 但不调整它的大小

ios - DismissViewController 关闭两个 UIViewController

ios - 如何在 swift 4 中设置对 collectionView 的关注?

ios - 在 Xcode 5 中,当我在源代码管理下添加服务器时出现错误

ios - UILabel TapGesture 未触发

ios - 获取 <BR> 和 : without <BR> inside the substring 之间的字符串

objective-c - 将数据从 ViewController 传递到 UIView

ios - 在 Swift 4 中创建特定的 Json

json - Swift 4 用 ' - ' 字母解码 json