Whe I create a new UIViewController and try to put inside a NavigationController in the usual way (drag-drop in the xib and create the outlet), I show the Navigationcontroller with:
[self.view addSubview:navigationController.view]
The result is a Navigation Bar with a little band in the upper part (seems displaced down), (i can't post the image now but is like 20px empty space)
I tried to put the navigation controller on the top window:
[[[UIApplication sharedApplication] keyWindow] addSubview:navigationController.view];
And it worked, but I'm unable to come back the initial screen whe I execute:
[navigationController.view removeFromSuperview]
or
[self dissmissModalViewControllerAnimated:YES];
It is possible to solve this?
UINavigationController* nav=[[UINavigationController alloc]init];
nav.navigationBar.frame=CGRectMake(0, 0, 320, 44);
NSLog(#"desc=%#",[nav.navigationBar description]);
[self.view addSubview:nav.navigationBar];
Try with above code. it will hide unnecessary space.
Thanks
20 pixels sounds like the status bar. Make sure in your nib that the status bar option for the view is set to None. Hope that Helps!
Related
When I use [[UIApplication sharedApplication] setStatusBarHidden:__ animated:__] to hide the status bar, I got a white space at the top of screen. I know it is for status bar. And if I just use a simple UIViewController as my main view controller I could set the view's frame to (0, 0, 320, 480) to cover the white sapce. But when I use UINavigationController, I don't know how to do that.
Anyone know this? Just give some advice if you don't have time to write code. I could use the advice you provided to do some research.
Thanks in advance.
I reckon you will have to access the view of the currentViewController in your UINavigationController and modify that views frame.
NSArray *controllers = [navController viewControllers];
// loop through and find the controller you want
// controller.frame.size.height= newHeight
You might need to change the view size of the root view controller too.
I have a UIViewTable with navigation bar. When I read data I display UIViewController with ActivityIndicator on top of the table. The problem is when I rotate device this top view is not rotating, I don't know why? :(
This is how I add top view with ActivityIndicator:
UIView *view = [[UIApplication sharedApplication] keyWindow];
[view addSubview:viewWithLoader.view];
This is how I remove it:
[viewWithLoader.view removeFromSuperview];
This is method from top view (with ActivityIndicator):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
after you call [self.window makeKeyAndVisible]; on your App delegate, the views that get the rotation notification, animation, etc, etc. are the subviews of that initial view.
It happen to me that I had a top bar that replaced the status bar. so I thought it will be a good idea to actually add it as a sub view of the key window. But that being the case resulted in the outcome you are experiencing.
You have 2 options
whoever owns that topview should take care of rotating it or remove/add it when a rotation occurs so it has the right orientation.
make that topview a subview of one of the views that ARE autorotating.
Both are really easy to implement but I found no. 2 is more visually attractive for the user.
I found solution :) I add this top view (with loader) as 'modal view' and rotation works fine in all views :)
...
[self presentModalViewController:ldr animated:YES];
...
[self dismissModalViewControllerAnimated:YES];
I have a UIImagePickerController that is shown
[self presentModalViewController:self.picker animated:NO];
Then later on the code, I allow the user to display a preference panel :
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:#"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];
At this point, the new controller raises on the screen, but don't go to the top.
Some space is left "transparent" at the top (I can see the camera view behind), and the bottom of the view is hidden out of the screen. The space I am talking about is about a status bar height. The status bar is not present on the screen.
The navigation controller is hidden :
self.navigationController.navigationBarHidden = YES;
There is a toolbar at the top of the view. Nothing special into the view.
The height of the view is defined at 480. All simulated element are set off in IB.
The autoresize properties are all set on.
I had a previous xib (I rebuilt it from scratch) that worked very well. I don't see what I missed on this one (I have only changed the xib, that replaces the previous one).
I've cleaned the cache to be sure there was nothing left. No change...
I've deleted everything in the new view to prevent some conflicts. No change...
What did I miss ? How could I remove this empty space ?
Try presenting the second modal view controller (the preferences one) from self instead of self.picker
ModalViewController loading on top of another Modal
Edit:
Try setting wantsFullScreenLayout = YES
After some searches and some other problems, I've found a final solution to the problem through this question
I had to call :
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
at the application start.
- (void)viewWillAppear:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
[navigationController setNavigationBarHidden:YES animated:YES];
}
The above code works perfectly fine and when the view is about to appear, a nice animation begins and after that, both the status bar and navigation bar are hidden.
BUT! My 320x480 view is not moved up to the top (0,0) as I want it to, but it is moved to where the navigation bar was, UNDER the (hidden) status bar. Where the status bar was, is blank, and the bottom of my view is cut off from the window. I find this rather strange because as you can see, I am using a UINavigationController to switch views and I am hiding the navigation bar as well, and the view does move 44px up, compensating the disappearing of the navigation bar. It just doesn't take the height of the status bar into account.
Same problem is on my camera view controller: a view in which camera is opening but view is not from top
Any one have idea how to fix this problem ?
Check out this post. I have done this several times. You should be all set.
How to set the top position = 0 after setStatusBarHidden:Yes?
The Code is:
Just a View:
[self.view setFrame: [self.view bounds]];
A view with a scroll view inside
[self.view setFrame: [self.view bounds]];
[self.theScroller setFrame: [self.view bounds]];
"theScroller is the name of my scrollview
I can't seem to get a UISearchBar to position itself from the far left to the far right in the navigation bar. In the -(void)viewDidLoad method, I have the following code:
UISearchBar *sb = [[UISearchBar alloc] initWithFrame:self.tableView.tableHeaderView.frame];
sb.delegate = self;
self.navigationItem.titleView = sb;
[sb sizeToFit];
[sb release];
When you build and run, it looks just fine at first glance. However, looking more closely, you can tell there is a margin/space on the left. This wouldn't be a big deal in the grand scheme of things, but when I tap the search bar to start a search, I animate the cancel button into view. Because the search bar is positioned slightly to the right, the animation is jerky and the cancel button falls off the end like so:
link text
It seems as if the UINavigationItem is like a table with three cells, where there is a padding on the first and last which I can't remove - nor does there seem to be a way to 'merge' it all together and then place the search bar there. I know this look is possible, because the AppStore search has a search bar in the navigation bar and it goes all the way to the edges. Anyone know how to get the search bar to go all the way to the edges so my slide-in cancel button animation will work properly?
Actually, there's a really simple solution. All you have to do is create a zero-width view for the back item:
UIView *hackView = [[UIView alloc] initWithFrame:CGRectZero];
UIBarButtonItem *hackItem = [[UIBarButtonItem alloc] initWithCustomView:hackView];
self.navigationItem.backBarButtonItem = hackItem;
[hackView release];
[hackItem release];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[searchBar sizeToFit];
self.navigationItem.titleView = searchBar;
[searchBar release];
Be sure to do this in your loadView method, not init. I'm not sure why that makes a difference, but it does.
Apparently it's about timing. Having it in loadView stopped working for me, but putting it in viewWillAppear works (with a check so that it's only done once, of course). I think the idea is to set the titleView after some initialization has already completed.
The following code hides the navigationBar just for this UIViewController:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
So to get the UISearchBar to show in the UINavigationBar's place, on your root view controller just have your search bar where the navigation bar would be normally!
I think I found out the answer - though I haven't tested to verify. In the issue I provided above, I have the following structure:
tab bar controller -> navigation controller -> view controller(s)
The search bar in question was in a view controller, which in turn was in the navigation controller, which navigation controller is in the tab bar.
I was casually watching the Stanford CS 193P (Spring 2009) courses and at the end of Lecture 13, the answer may have been presented. Alan Cannistraro stated that the structure of the Presence app should have this structure:
this structure http://img143.imageshack.us/img143/6/viewcontrollerstructure.jpg
where the bottom view controller (adjacent to the tab bar controller) was the view controller which had the search bar control. He warned if it's not done in this fashion, you'll "run into problems". Possibly the problem I faced? I believe so.
Maybe apple is using an UISearchDisplayController for doing these kinda things.