Adding perspective

Before we can animate our z axis, we need to add perspective to our user interface.

Replace the buildCircleLayers method with the following code:

func buildCircleLayers() {   for i in 0..<colors.count  {     let  layer = CALayer()     layer.bounds = CGRect(x: 0.0,                           y: 0.0,                           width: 40.0,                           height: 40.0)     layer.position =  CGPoint(x: 130,                               y: 40)     layer.zPosition = CGFloat(-3 * i)        layer.borderColor = colors[i]     layer.borderWidth = 2.0     layer.cornerRadius = layer.bounds.width * 0.5     circleLayers.append(layer)     cosmicDoor.addSublayer(layer)   }   var perspective = CATransform3DIdentity    perspective.m34 = -0.2    cosmicDoor.sublayerTransform = perspective}  

We iterate through the colors array, as we have done before, and as you can see, ...

Get Mastering macOS Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.