开发者

Pushed UIViewController's view is always as big as fullscreen

in an iPad application, I am displaying a modal view controller (through presentModalViewController) in a FormSheet style (so it's about 540 pixels wide and high), the root view controller displays fine (its frame's size is set to roughly (540, 540) and my code takes care of laying out the content properly).

However, when a push a view controller, its frame's size always has (768, 1024) which is wrong. I tried to set its frame explicitly like this:

DetailViewController* detailController = [[DetailViewController alloc] init];
detailController.view.frame = self.view.frame;          
[self.navigationController pushViewController:detailContro开发者_运维知识库ller animated:YES];

Any ideas why it doesn't set the size properly?


well, layoutSubviews should be used if the actual frame of the view at runtime is needed. I ended up using that to lay the subviews inside the controller's view. (although I had to create a custom UIView subclass for controller's view)


Your approach looks right. Forgive my question, but have you debugged this with breakpoints and GDB?

You might try this from the console (cmd shift r):

print [[self view] frame]

and

print [[detailController view] frame]

print this before and after you call pushViewController:animated on the UINavigationController to see if its frame size changes from the pushViewController:animated method.

Another note, its hard to see a use case for pushing a view controller to a UINavigationController that would NOT consume the entire UINavigationController's views area. Every push onto the navigation controller represents a level deeper into some navigation (unlike UIView - addSubView).

http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

Update: This is why you are having problems:

The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.

You will find that on apple's documentation on the link I provided. See pushViewController:animated:


View controllers are expected to manage an entire "screenful" of content. Only one view controller (not counting container controllers like UINavigationController) is active at any given moment. The only exception is UISplitViewController, which allows two view controllers to have content on the screen at once.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜