Unhiding the navigation bar after popping a UIPageViewController - ios

I am having trouble trying to unhide the navigation bar in my app. I have a UIPageViewController created in a UIViewController like so:
//Hide the bar
self.navigationController.navigationBar.hidden=YES;
// Create page view controller
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:229/255.0 green:145/255.0 blue:217/255.0 alpha:1];
pageControl.backgroundColor = [UIColor whiteColor];
//Call our helper method
StickerContentViewController *startingViewController = [self viewControllerAtIndex:0];
//Need to pass the first one, don't put them all in here
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//setup
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
When I pop the UIViewController (the one containing the UIPageViewController) using [self.navigationController popViewControllerAnimated:YES]; I can't get the navigation bar to unhide for the previous screen. I have tried placing self.navigationController.navigationBarHidden=NO; in the viewWillDisappear, viewDidDissappear. I also tried putting it in the content view controller but still no luck. Could someone give me a pointer to what I might be doing wrong here please?

Fixed it, just posting in case someone else has an issue. I was using self.navigationController.navigationBar.hidden=YES; when I should have used self.navigationController.navigationBarHidden=YES;. Not sure what the difference is. Anyway I hide the bar in the viewDidLoad and unhide it in the viewWillDisappear and it works now. thanks guys

Related

How to add and remove searchBar from navigationItem

I am having trouble adding and removing a UISearchControllers searchBar to a UINavigationBar.
Here is what I am doing:
Add the searchBar to the view
searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
searchController.searchResultsUpdater = self;
searchController.searchBar.delegate = self;
searchController.dimsBackgroundDuringPresentation = NO;
searchController.hidesNavigationBarDuringPresentation = NO;
searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;
searchController.searchBar.barTintColor = [UIColor blackColor];
searchController.searchBar.tintColor = [UIColor darkGrayColor];
[searchController.searchBar setFrame:CGRectMake(0, 200, 320, searchController.searchBar.frame.size.height)];
[self.view addSubview:searchController.searchBar];
On button click add the searchBar to the navigationItem
This works as expected
[self.navigationController setNavigationBarHidden:false];
self.navigationItem.titleView = searchController.searchBar;
self.navigationItem.hidesBackButton = true;
And here is where I am getting the strange behaviour:
On another button click remove the searchBar from the nav bar and add it back to the view
[searchController.searchBar removeFromSuperview];
[self.navigationController setNavigationBarHidden:YES animated:true];
[self.view addSubview:searchController.searchBar];
[searchController.searchBar setFrame:CGRectMake(0, 200, 320, searchController.searchBar.frame.size.height)];
The searchBar is removed from the Nav Bar as expected, but it is not returned to the main view. ( well i can't see it anywhere)
I log the value of the search bar I can see that it has the frame that I have given it.
Any help here would be greatly appreciated,
Thanks
You should set navigationItem .titleView to nil first and setFrame: in main thread.
- (IBAction)addBar:(id)sender {
self.navigationItem.titleView = nil;
[searchController.searchBar removeFromSuperview];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationItem.titleView = searchController.searchBar;
self.navigationItem.hidesBackButton = YES;
}
- (IBAction)removeBar:(id)sender {
self.navigationItem.titleView = nil;
[searchController.searchBar removeFromSuperview];
[self.view addSubview:searchController.searchBar];
[self.navigationController setNavigationBarHidden:YES animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self->searchController.searchBar setFrame:CGRectMake(0, 200, 320, self->searchController.searchBar.frame.size.height)];
});
}
By the way, I think it is better that put the search bar in a wrapper UIView when adding to the navigationItem.titleView.

iOS How can I set transparent in Container viewcontroller

I had embed UIPageViewController in the Root Viewcontroller.
Like below photo .
But I want to set First,second View controller background transparent, and it's still can show view controller text 1 and 2.
So It will show Root background color(black) and the root view controller can swipe though the uipageviewcontroller.
My pageviewcontroller part code below:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro1ID"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro2ID"];
myViewControllers = #[p1,p2];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
Have anyone can teach me how to set the containerview background color transparent and can show 1 , 2 text?
(It is sample code, so that just 1, 2 text)
thank you very much.
This should do the trick:
[[p1 view] setBackgroundColor:[UIColor clearColor]];
[[p2 view] setBackgroundColor:[UIColor clearColor]];
The issue is that the background view of your UIViewController was not transparent.

Add Custom View on UIPageViewController

I want to add a Custom View (red View) on the bottom of my UIPageViewController like this:
Because i want some Standard Text which is displayed on every View of my UIPageViewController. Everythings works fine, but my Custom VIew is not visible, this is what i tried:
- (void)viewDidLoad
{
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
FirstTutorialViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
//Here i try to set the Custom view:
[[self.pageController view] addSubview:[self customView]];
Don't add self customView to the page controller, and be sure to set its frame first.
Instead, resize the page controller to allow space at the bottom for the custom view and add both to your main view.

How to remove split second white screen between dismissing a view controller and loading a new view controller

I'm using this to dismiss the view controller.
[self dismissViewControllerAnimated:YES completion:nil];
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.view.alpha = 0.0;
[UIView animateWithDuration:0
animations:^{self.parentViewController.view.alpha = 1.0;}];
self.parentViewController.view.alpha = 1.0;
But it is still displaying the white screen before it displays the view controller and I have even changed all my components to a different colour to see if it was a component but the screen stayed white.
check out this code:-
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:modalVC animated:YES];

top bar in UIPageViewController

I based my application with the default "Page-based App" in Xcode. I'm trying to display a navigation bar on top of my DataViewController in my storyboard without using a navigation controller. The problem is, when I swipe left and right, the navigation bar seems to go along with the gesture. How can I make it "not-movable"?
Things I tried:
Putting the navigation bar in my RootViewController instead. When I simulate the app, the navigation bar is not visible.
EDIT:
RootViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Configure the page view controller and add it as a child view controller.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;
GJDataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
self.pageViewController.dataSource = self.modelController;
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
CGRect pageViewRect = self.view.bounds;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
}
self.pageViewController.view.frame = pageViewRect;
[self.pageViewController didMoveToParentViewController:self];
// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
}
DataViewController.m
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.dataLabel.text = [self.dataObject description];
}
Follow these steps:
Use your 2nd trial: "Putting the navigation bar in my RootViewController instead." to make navigation-bar immovable with every age transition.
Now in RootViewController.m, change the line CGRect pageViewRect = self.view.bounds; to CGRect pageViewRect = CGRectMake(self.view.bounds.origin.x, 64, self.view.bounds.size.width, self.view.bounds.size.height-64); .Where 64=20(status-bar height) + 44(navigation-bar) height.
2nd step will adjust frame of your DataViewController's view below added navigation-bar in RootViewController and thus navigation-bar will not hide.
Hope, it helps you....Happy Coding! :-)

Resources