I am trying to execute following code in viewDidLoad method of my single view controller project:
self.view.layer.frame = CGRectInset(self.view.layer.frame, 20,
The viewDidLoad
method is too early to set your view's frame because something else is changing the frame later.
For example, if this is your root view controller, then the UIWindow
object will set the view's frame when it adds the view to itself as a subview. The viewDidLoad
method runs as soon as loadView
returns, before any outside object (like the UIWindow
) can get its hands on the view.
You can test this by using a custom view (if you're not already) and overriding setFrame:
in the custom view class:
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
}
Put a breakpoint in that method and you'll see that the view's frame gets set some time after viewDidLoad
returns.