Why doesn't self.bounds.size.height ignore the UINavigationView navigation bar in this code?

I have a UITableView configuration that can start the color picker using the UINavigationController approach:

[self.navigationController pushViewController:colorPickerViewController animated:YES]; [colorPickerViewController release]; 

The effect of this means that ColourPicker will have a navigation bar at the top (and a back button)

The structure of the ColourPickerViewControll and view of the ColourPickerView is as follows:

 - ColourPickerViewController - in it XIB file at the top level view it has: - ColorPickerView : UIView (ie custom UI view) - in it methods it has: - (id)initWithCoder:(NSCoder*)coder { if ((self = [super initWithCoder:coder])) { CGFloat currVertBounds = self.bounds.size.height; 

The problem here is that the value of currVertBounds reaches 480, so it does not take into account the navigation bar

QUESTION: How to get the true display height of a ColorPickerView instance?

Is this somehow related to an attempt to get a layout calculated in a custom UIView, and maybe the custom view is not displayed in the general controller / navigation at this stage?

+7
source share
3 answers

You read bounds too soon. None of the layout / spy mask that occurs in UIKit will pass during [super initWithCoder:] . You should read bounds and expose your view:

  • In viewDidLoad / viewWillAppear and configure the autosave settings for all manually created user interface elements so that they can move around different orientations of the interface. In these functions, I would not rely on bounds to be exact, but I would say that this is at least the correct proportion of height: width. Perhaps this may be the wrong orientation.
  • In viewDidAppear , if you want to manually position elements. By the time you click viewDidAppear all the resizing has happened, and this has happened, and the only thing to worry about is future rotations that you must configure for your view in willAnimateRotationToInterfaceOrientation:duration:

Documents at willAnimateRotationToInterfaceOrientation:duration: state:

By the time this method is called, the interfaceOrientation property is already set to a new orientation. Thus, you can execute any additional layout that your ideas in this method need.

iOS 5.0 docs add sentence:

... set a new orientation, and the borders of the view are changed. Thus,...

I think this still applies to previous versions of iOS.

+7
source

Views for iPhone will, by definition, be 480 pixels high when created in Interface Builder, so you'll see when you initialize the view. After the view has been correctly initialized and added to the view stack, it will be modified to match the actual available space.

You just ask for an idea of ​​its height before it is set up. Try to read the height in viewDidLoad , then this should be correct.

+1
source

Yes, that’s right, because the UINavigationController instance is declared in your (delegate.h) and that the navigationBar is not added to the window on self.view

When you check the borders of your current view, it must definitely return 320 * 480. It should not include the height of the navigation bar in your view, since it is not in this view. His window.

0
source

All Articles