I use a translucent navigation bar and status bar, and my View Controller is full screen. In this way, the View View View View expands below the Nav and Status lines and displays the full screen size.
I also have a shortcut that I would like to align right below the navigation bar. Since I cannot add restrictions directly between the shortcut and the navigation bar, I add my restriction between the top of the label and the top of its parent view. I set the contrast constant equal to the height of the status bar + the height of the navigation bar.
The problem is that during the rotation between Portrait and Landscape, because the height of the navigation bar changes, and I need my shortcut to rotate well too, so I need to know the new height of the navigation bar in willRotateToInterfaceOrientation:
I use this method to ensure that the shortcut is in the right place when the view controller moves from a portrait or landscape. It works great.
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Get Y origin for Label CGFloat navBarY = self.navigationController.navigationBar.frame.origin.y; CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height; CGFloat labelY = navBarY + navBarHeight; // Set vertical space constraint for Label self.labelConstraint.constant = labelY; }
I use this method to change the label when the orientation changes, since the height of the navigation bar changes from 44 pixels to 32 pixels. The problem is that I need to get the NEW altitude at which the navigation bar WILL BE after rotation before rotation actually occurs.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
For fun, I tried to set the beginning of Y for the label after rotation in didRotateFromInterfaceOrientation: but, as expected, it will not be smooth and the label will snap after the rotation is completed.
Thanks in advance for your help!