ARTICLE AD BOX
I need a ready-made code for the 1:1 cutout shape of a MacBook. I have the code, but it's not exactly 1:1; the curves at the top don't match up quite right. If there are other alternatives besides the Shape protocol, but it is possible to flexibly configure the frame for any events, that will also work.
struct NotchShape: Shape { var bottomCornerRadius: CGFloat = 13 var topCornerRadius: CGFloat = 6 var animatableData: AnimatablePair<CGFloat, CGFloat> { get { AnimatablePair(bottomCornerRadius, topCornerRadius) } set { bottomCornerRadius = newValue.first topCornerRadius = newValue.second } } func path(in rect: CGRect) -> Path { let w = rect.width let h = rect.height let rBottom = min(bottomCornerRadius, min(w, h) / 2) let rTop = min(topCornerRadius, min(w, h) / 2) let k: CGFloat = rTop * 1 var path = Path() path.move(to: CGPoint(x: rTop, y: 0)) path.addCurve( to: CGPoint(x: 0, y: rTop), control1: CGPoint(x: -k * 1.8, y: 0), control2: CGPoint(x: 0, y: -k * 0) ) path.addLine(to: CGPoint(x: 0, y: h - rBottom)) path.addQuadCurve( to: CGPoint(x: rBottom, y: h), control: CGPoint(x: 0, y: h) ) path.addLine(to: CGPoint(x: w - rBottom, y: h)) path.addQuadCurve( to: CGPoint(x: w, y: h - rBottom), control: CGPoint(x: w, y: h) ) path.addLine(to: CGPoint(x: w, y: rTop)) path.addCurve( to: CGPoint(x: w - rTop, y: 0), control1: CGPoint(x: w, y: -k * 0), control2: CGPoint(x: w + k * 1.8, y: 0) ) path.closeSubpath() return path } }