Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView created in IB has no frame in viewDidLoad and awakeFromNib

Tags:

ios

uiview

I'm sorry if I missed something here, but I thought UIView objects that were created in IB should have their frames created in viewDidLoad so you can do initial setup based off of this view in viewDidLoad or awakeFromNib or viewWillAppear. I logged the output in each method:

NSLog(@"%@ %s", NSStringFromCGRect(self.zoomView.frame), __FUNCTION__);

And in all I get {0, 0, 0, 0}.

This is the first nib in my UIStoryboard, and I'm using Autolayout and iOS 6. I could have sworn on previous apps I have used the frame of other UIView objects created in IB to set things up. Is there something that has changed? Or do I just remember it incorrectly? Thanks!

like image 363
Crystal Avatar asked Oct 05 '22 15:10

Crystal


1 Answers

I had the exact same issue. Yes, you remember correctly - it used to be different in iOS 5. I always set up my views in viewDidLoad: and the frame was already the way it was going to be when the view was actually on screen.

Now in iOS 6, you'll need to put your code into viewDidAppear: to have a valid frame to work with, if auto layout is enabled. Apparently the laying-out is done in between those two calls.

like image 125
Double M Avatar answered Oct 10 '22 20:10

Double M