When adding a subview it will be placed above all other subviews. However, after adding a subview you can changes it’s layer position. There are 3 main ways of playing with the layering of views.
The following technique will place a view above all other subviews:
view.bringToFront()
The following will place a view below all other subviews:
view.sendToBack()
The following will swap the z-positions of two views:
view.positionAbove(shape)
shape.positionBelow(view)
You can also explicitly set the z-position of a view:
shape.zPosition = 1000
var circles = [Circle]()
override func setup() {
for i in -1...1 {
let c = Circle(center: canvas.center + Vector(x: 100, y: 0) * Double(i), radius: 100)
c.lineWidth = 25
canvas.add(c)
circles.append(c)
c.addTapGestureRecognizer { locations, center, state in
self.canvas.bringToFront(c)
}
}
}