开发者

Why is self.bounds.size.height not taking into account the UINavigationView nav bar in this code?

I have a configuration UITableView that can launch a colour picker via a UINavigationController approach:

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

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

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

- ColourPickerViewController - in it's XIB file at the top level view it has:
  - ColorPickerView : UIView (i.e. custom UI view) - in it's methods it h开发者_如何学JAVAas:
    - (id)initWithCoder:(NSCoder*)coder  {
       if ((self = [super initWithCoder:coder])) {
         CGFloat currVertBounds = self.bounds.size.height;

The issue here is the the value of currVertBounds is coming to 480, so it's not taking account of the navigation bar

QUESTION: How do I get the true displayed height of the ColorPickerView instance?

Is it something to do with trying to get the layout calculated in the custom UIView, and perhaps the custom view isn't rendered within the overall controll/navigationController at that stage?


You're reading bounds too early. None of the layout/subviewing magic that happens in UIKit will take place during [super initWithCoder:]. You should be reading bounds and laying out your view either:

  1. In viewDidLoad/viewWillAppear, and set up the autosizing parameters for all manually created UI elements so they can get moved around with respect to different interface orientations. In these functions I wouldn't rely on bounds being exactly correct but I would say it's at least the right height:width ratio. It could possibly be in the wrong orientation, though.
  2. In viewDidAppear, if you wish to manually position elements. By the time you hit viewDidAppear all of the resizing and such has taken place, and the only thing left to worry about is future rotations, which you should adjust your view for in willAnimateRotationToInterfaceOrientation:duration:.

Docs on willAnimateRotationToInterfaceOrientation:duration: state:

By the time this method is called, the interfaceOrientation property is already set to the new orientation. Thus, you can perform any additional layout required by your views in this method.

iOS 5.0 docs add the clause:

...set to the new orientation , and the bounds of the view have been changed. Thus...

I think this is still the case for prior iOS versions.


Views for iPhone will by definition have a height of 480 pixel when created in Interface Builder, so that's what you're seeing when you're initializing the view. Once the view has been properly initialized and added to the view stack, it will be resized to match the actual space available.

You're simply asking the view of its height before it has been adjusted. Try reading the height in viewDidLoad, then it should be correct.


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

When you check the bounds of your current view, it should definitely return 320 * 480. It should not include height of navigation bar in you view, as it not on that view. Its on window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜