To begin with, add the following method to the ViewController class:
func buildTransformLayer() { let sideLength = CGFloat(160.0) let rightAngle = CGFloat(M_PI) * 0.5 transformLayer = CATransformLayer() func sideLayerWithColor(_ color: CGColor) -> CALayer { // code to follow } func addLayersToTransformLayer() { // code to follow } addLayersToTransformLayer() transformLayer.anchorPointZ = sideLength / -2.0 applyRotation(xOffset: 6.0, yOffset: 8.0) customView.layer?.addSublayer(transformLayer) }
We'll get to the locally defined methods in a moment, but first let's see what we've got here:
- We declare a couple of constants and initiate the transformLayer property of the ViewController ...