I have a simple test app that has one view, one view controller, and all of this is instantiated via a standard storyboard. When I run my app and pause on a breakpoint in my view controller I can see that the following values are set on the view:
self.view.layer.position = (CGPoint) (x=160, y=294)
self.view.layer.frame = (CGRect) (origin=(x=0, y=20) size=(width=320, height=548))
self.view.layer.visibleRect = (CGRect) (origin=(x=0, y=0) size=(width=320, height=548))
I understand the initial origin value for the frame (assuming the value of 20 is an offset for the status bar), but where is the 160/294 value coming from for the layer's position? I'm baffled by this one.
This is because a CALayer's position property is relative to its anchorPoint
. By default, the anchorPoint is set to (0.5, 0.5), which represents the center of the layer's bounds.
If you're trying to perform very basic positioning changes programmatically, I'd stay away from your view's layer property, since UIView has positioning properties of its own.