MarkRS
01/05/2022, 10:50 AMSam
01/05/2022, 3:07 PMMarkRS
01/05/2022, 4:21 PMSam
01/05/2022, 5:00 PMMarkRS
01/05/2022, 5:13 PMSam
01/05/2022, 6:03 PMMarkRS
01/05/2022, 6:23 PMSam
01/05/2022, 6:30 PMMarkRS
01/05/2022, 6:39 PMSam
01/05/2022, 7:21 PMexpect class CommonPath {
// drawing methods
}
interface class CommonPath {
// drawing methods
}
class CommonPoint(x: double, y: double)
In Swift you would implement it.
class SwiftPath extends CommonPath {
private let path = UIBezierPath()
// drawing methods
override func lineTo(point: CommonPoint) {
path.addLineTo(point.toCGPoint())
}
}
extension CommonPoint {
func toCGPoint() -> CGPoint {
return CGPoint(x: CGFloat(self.x), CGFloat(self.y)
}
}
class ShapeMaker(private val pathCreator: () -> CommonPath){
fun makePath() {
val path = pathCreator()
...
}
// Or
fun makePath(path: CommonPath) { ... }
}
In the swift calling code:
let shapeMaker = ShapeMaker() { SwiftPath() }
// Or
shapeMaker.makePath(path: SwiftPath())
MarkRS
01/05/2022, 7:59 PMSam
01/06/2022, 3:23 PMcgPath
property on it that you can use where necessary. Most of the custom drawing I’ve done, I start with a UIBezierPath and just use the cgPath property when calling lower level apis.SwiftPath
class name I used above was just an example name. You would call it whatever made sense to you.MarkRS
01/06/2022, 4:53 PMSam
01/06/2022, 5:06 PMMarkRS
01/06/2022, 5:07 PMSam
01/06/2022, 5:29 PMMarkRS
01/06/2022, 5:35 PMSam
01/07/2022, 4:21 PMif #available(iOS 15.0, *) {
blocks. It’s not the best.