In my iPad application i need to implement a navigation controller behavior to the right half of the screen( I can't use split view controller because i need more space in left-side - around 600px). Is there any way to create a NavigationController with a fixed frame size ?
thanks in Advance.
You should simply:
create navigation controller;
set navigationController.view.frame to necessary frame;
add navigationController.view as you main view's or window's subview.
Somsing like this:
navigationController.view.frame = necessaryFrame;
[viewController addSubview:navigationController.view];
Related
I haven't been able to find anything on this and feel it likely isn't possible in a simple manner.
Can I have a view, such a loading bar for example which constantly sits over every other view controller until I choose to dismiss it but at the same time any underlying view can still be interacted with? Sort of acting like a system view. Be persistent when presenting new view controllers and all.
Thanks.
Add it as a subview of your window. Like this:
UIView *myView = ...
[self.window addSubview:myView];
Rather than adding it to the window, as #JackyBoy suggests, add it to the window's rootViewController's view. That will rotate along with the device. If you just add it to the window, you may have problems with rotation.
UIView *myView = ...
[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:myView];
I have an application where I'm trying to duplicate what I see the Apple Store app doing, where the first view doesn't have a navigation bar, but subsequent views do.
I've tried various combinations of setting navigationBarHidden to YES and NO to manage when it's visible, but the key problem seems to be that during the transition, it's either visible or it isn't, whereas in the Apple Store app, the navigation bar is not there in the main view, but slides in from the right with the child view.
What I'm looking for is a way to have the navigation bar slide in with the child view, not appear (animated or not) before or after the transition.
Turns out I just hadn't hit on the right places to hide and show the navigation bar.
I used the answer from how to hide navigationbar when i push from navigation controller? and it works great for me now.
in your main view, initialize the childViewController. Then set the nav bar on the childViewController, the push the view controller.
ChildVC *childVC = [[ChildVC alloc] initWithNibName:#"ChildVC" bundle:nil];
[self setChildVC:childVC];
childVC.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:childVC animated:YES];
If you are talking about what they do on the first Tab "Featured", where if you tap one of the items in the list with a disclosure indicator. It appears to slides in another view from right to left. I think they are using an animation to swap two view controllers. The one that slides in IS a Navigation controller which is why NavBar appears to slide in from the right.
You would do something like this to get that effect:
// First set up a view controller with frame set off to the right of the screen.
// Then animate it sliding to the left by setting its frame x = 0;
frame.origin.x = 0;
[UIView animateWithDuration:.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^{
vc.view.frame = frame;
}
completion:nil];
I have a view controller, but when I hide the tab bar, there is just a black space where the tab bar was. I want to have my view controller sit behind the tab bar, so when I hide it, it shows the view content. I am using a simple UITabBarController. Thanks.
You can't do this, as far as I'm aware. The problem is that the view controllers sit within the tab bar controller, not the other way around.
The way to get around this would be to change the window view for a new navigation controller without a tab bar controller, or use a modal view to show content without a tab bar controller.
The problem is that your view on your view controller isn't tall enough to accommodate the space that your tab bar occupied.
CGRect current = [[self view] frame];
CGRect tabBarFrame = [[self tabBar] frame];
CGRect newFrame = CGRectMake(current.origin.x, current.origin.y, current.size.width, current.size.height + tabBarFrame.size.height);
[[self view] setFrame:newFrame];
Something like that is probably what you want. Or you can resize it in IB.
But, I don't know why you would use a UITabBarController and then hide the tab bar... If you can't see the tab bar, you cant switch tabs... thus making the UITabBarController pretty much just a UIViewController.
I believe that if you give the view property of your UIViewController a fixed bottom margin and a flexible height then it will stretch to fill the height of containing view automatically.
mycontroller.view.autoresizingMask = UIViewAutoresizingFlexibleHeight
I have several UIViewControllers, loaded via a UINavigationController, where I override loadView, and setup a custom view to display. I am having problems with setting the frames of some of the subviews, and maybe the view itself. I think that either the UINavigationController or the UIViewController is able to force it's view to fill the screen when displayed.
I am wondering if and/or when the size of the view is set. And if it is happening, is it setting the frame of the view, or doing it another way.
Thanks.
Update:
I have just noticed while working through this is that I make an new UINavigationController, with this loadView method:
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 10.0f, 10.0f)];
[view setBackgroundColor:[UIColor redColor]];
self.view = view;
[view release];
}
I get a red view taking up the entire screen, except for the status bar and header. When does my view get resized to fill the screen? And what size should I use when creating the view?
UINavigationController will automagically size a ViewController's view when pushed. From the docs:
pushViewController:animated:
The object in the viewController parameter becomes the top view controller on the navigation stack. Pushing a view controller results in the display of the view it manages. How that view is displayed is determined by the animated parameter. If the animated parameter is YES, the view is animated into position; otherwise, the view is simply displayed in place. The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.
If you want to have a smaller view displayed then you'll have to create a container and make it a child of your VC's view, setting the size manually. The autoresize mask may have to be set properly, depending on how you create the view.
The framespace for the UIViewControllers becomes smaller, because UINavigationController manipulates the view by adding a UINavigationBar, which is 44.0f in size.
It gets resized because you replace the view with self.view = view; If you would have used addSubview: instead it would have stayed it's original size. logancautrell explained when and why.
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:detailController 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.