I have created a new single view project written in swift and print self.view.layer.sublayers.count
. The number is 2, but I haven't add any layer or UIView.
override func viewDidLoad() {
super.viewDidLoad()
println(self.view.layer.sublayers.count)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
I wonder what the extra two layers are.
Every
UIView
is backed up by aCALayer
, the view hierarchy and the layer hierarchy are connected to each other.If you print out the
subviews
, you will see that the view has two subviews of type_UILayoutGuide
which represent the controller'stopLayoutGuide
andbottomLayoutGuide
. Every subview has a layer so that's your 2 sublayers.To prove it:
prints: