PresentModalViewController overlaps the navigation bar and status bar iOS 7 - ios7

I resolved the navigation bar status bar issue in all my views, but when I use presentModalViewController to show another view, navigation bar and status bar overlaps again.I am using this for presenting new view:
[self.parentViewController presentModalViewController:newController animated:YES];
Any idea to why this is happening?

Try this code
1.your viewcontroller
UIViewController *View=[[UIViewController alloc]init];
2.If u need Navigation bar add this code
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:View];
nav.modalPresentationStyle=UIModalPresentationFormSheet;(presentingModal view)
[self presentViewController:nav animated:YES completion:nil];

For me, it worked by
pushing the navigation bar and other views by 20 pixels for the view that i was presenting as modal view controller
setting the black color background for status bar in viewDidload by:
UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 20)];
statusBarView.backgroundColor = [UIColor blackColor];
[self.view addSubview:statusBarView];

Related

Change appearance of UINavigationBar from solid to transparent

I want to achieve the exact same effect as the Photos app on the iPad: solid black navigation bar during the gallery controller, then transparent when viewing a photo.
After I initialize my navigation controller in the AppDelegate I can change the style using the below code, but not outside the AppDelegate. However once the navigation controller is on screen and set once, navigationBar becomes a read-only property.
I would greatly appreciate if someone can share how this is done. Thanks.
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
UINavigationBar in UIBarStyleBlackTranslucent barStyle doesn't fix it's place as it normally does in other styles. In UIBarStyleBlackTranslucent style it just overlaps on your view and contents of views are translated up and view height is also increased.
if you're showing photos then first hide your navigationBar :
[[self navigationController] setNavigationBarHidden:YES animated:NO];
Now set your navBar's style to UIBarStyleBlackTranslucent
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
Then show your imageview (or scrollview with picture- depends on your logic). Then on tapping on your imageview you can show and hide bar)
// Show/Hide bar
// Let say you've a bool 'shown' for current status of navbar's visibility.
if (!shown) {
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}else{
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
shown = !shown;
Hope this'll do it. ANd never forget to rechnage barStyle to UIBarStyleBlackOpaque once you exit gallery.
Seems like you want to display navigationBar at the Gallery so there no need to change anything but after selecting a photo, keep the NavigationBar hidden in the PhotoViewController.
-(void) viewDidLoad
{
self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent;
self.navigationController.navigationBar.hidden = NO;
}
and in ViewWillAppear
-(void) viewWillAppear
{
self.navigationController.navigationBar.hidden = YES;
}
And then create a custom method implementing UITapGestureRecognizer where on a single tap display the navigationBar by setting hidden property to YES.

How to remove status bar from Modal ViewController in iOS App

I am working on a Children's book app for iPad and my app opens up an Modal Window to be able to select Male or Female Narrator. I am unable to remove the status bar from the Modal Window. Pls. see attached screenshot (highlighted in yellow color). Also, how do I make the window look pretty or make is transparent as it doesn't look too appealing at the moment?
Here is the code logic to open the ModalViewController inside my Main Controller:
-(IBAction)appLinkGet{
[self loadSetupModalView];
}
-(void)loadSetupModalView{
NSLog(#"ChildrenBookViewController ==> loadSetupModalView::");
// Create a Navigation controller
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.setupViewController];
//RESIZE THE MODAL VIEW
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:navController animated:YES];
navController.view.superview.autoresizingMask =
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
navController.view.superview.frame = CGRectMake(
navController.view.superview.frame.origin.x,
navController.view.superview.frame.origin.y,
540.0f,
400.0f
);
//navController.view.superview.center = self.view.center;
[navController release];
}
Try using this method:
[navController setNavigationBarHidden:YES animated:NO];

How to set title on the navigation bar for different buttons on a single view?

My app for iPad has 3 views. Welcome Screen -> Home screen -> Detail screen
Home screen has 6 buttons. All those buttons have different data which is shown on detail screen respective to the button pressed. I want to set a title for each button on the navigation bar of the Detail Screen. So there will be 6 titles on the navigation bar. I have tagged the buttons from 1 to 6.
pls guide
thanks
If you have Navigation Controller, then all you need is to set title property of Detail screen's View Controller. Navigation bar will automatically update it's label to current View Controller's title.
So if you have action for button :
- (IBAction)buttonPressed:(id)sender {
UIButton *button = (UIButton *)sender;
NSString *title = [button text];
DetailScreenViewController *detail = [[DetailScreenViewController alloc] initWithDetail:title];
[detail setTitle:title];
[navigationController pushViewController:detail animated:YES];
[detail release];
}
Before you push the view controller, set the title for it.
thisViewController.title = #"My Title";
[navigationController pushViewController: thisViewController animated:YES];
When updating the view with new content, update the view controller's title:
viewController.title = #"New Title";

how to add navigation bar UISearchBar

// self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
// UIBarButtonSystemItemAdd target:self action:#selector(addWord)] autorelease];
with this i can add button to rightside to the naivation bar.
How to add UISearchBar in middle to the navigation bar.
I am not sure why you want the UISearchBar on the navigation bar. Normally the implementation is just below the Navigation bar, and you can set it as your tableHeaderView
But for adding the Searchbar to your navigation bar, you cannot add the UISearchBar directly. You can add the Navigation Bar, and your UISearchBar as subviews to a view (lets say comboView) and then add it to your self.view or your tableHeaderView.
UIView * comboView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
[comboView addSubview:navigationBar];
[comboView addSubview:searchBar];
// You should have allocated the navigation bar and the search bar before this though.
self.tableView.tableHeaderView= comboView;

UIScrollView shifts below navigation and status bar

I have view which contains a scrollView. When the view shows up the image appears in full screen (320x480) hiding the status and navigation bar. When I tap the screens - status and navigation bar appears on the screen. But this thing shifts the UIScrollView below the the navigation bar. I want the status and nav bar to show over my scroll view.
Like it happens in the photos app. On tapping the image the status and nav bar shows over the scrollView.
Below is how I am positioning the view
//What I have done in viewDidLoad
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
self.wantsFullScreenLayout = YES;
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = scrollView;
Below is what I am doing on detecting a single tap
- (void)tapDetectingImageView:(TapDetectingImageView *)view gotSingleTapAtPoint:(CGPoint)tapPoint {
// single tap hide/unhide the status and nav bar
NSLog(#"got a single tap");
if (self.navigationController.navigationBarHidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
}
Just a pointer for you guys -
If I use [self.view addSubview:scrollView]; I dont see this issue. But this mess up my landscape orientation code.
Anyone who can shed some light what I might be doing wrong - would be great help!
There appears to be some special handling inside UIScrollView when the navigation toolbars are toggled. As you pointed out at the end of your question, if you put the scroll view inside a containing UIView, this repositioning problem does not occur.
To fix the landscape issues, make sure you're setting the autoresizingMask on both the container view and the scroll view. I did not have to add any additional handling for landscape mode in my project.
I found the solution myself.
In my tap detecting code's else fn I add the below line in the last.
scrollView.contentOffset = CGPointMake(parentScrollView.contentOffset.x,0);
Not sure if this is the right approach. But if anyone can suggest a better approach - more than welcome!