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! :-)
Related
This is my code:
VideoDetailViewController *VideoDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"VideoDetailViewController"];
UINavigationController * navigationController = (UINavigationController *) [[self tabBarController] selectedViewController];
[self.tabBarController setSelectedIndex:0];
[navigationController pushViewController:VideoDetailVC animated:YES];
I am writing this code in tabbar's second index. I want to directly go to the Video Detail screen, which is child view controller of tabbar's zero index. Everything works fine but what I see is: it shows a parent view controller which is tabbar's zero index. After a second it pushes to the Video Detail screen. I just don't want to show the zero index. What is the solution? Help will be appreciated.
EDITED:
#import "TWPhotoCollectionViewCell.h"
#implementation TWPhotoCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.imageView.layer.borderColor = [UIColor blueColor].CGColor;
[self.contentView addSubview:self.imageView];
}
return self;
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
self.imageView.layer.borderWidth = selected ? 2 : 0;
}
#end
Replace below line
[navigationController pushViewController:VideoDetailVC animated:YES];
With
[navigationController pushViewController:VideoDetailVC animated:NO];
It may solve your issue.
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
Basically, I am trying to present a custom modal view with a specific size and position since I was able to manage this through popover on iOS 7. But on iOS it seems they change things.
I manage to achieve this with the following:
Presentation:
UpViewController *upViewController = [[UpViewController alloc] init];
upViewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:upViewController];
navigationController.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:navigationController animated:YES completion:nil];
In UpViewController.m:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.navigationController.view.superview.bounds = CGRectMake(-350, -30, 320, screenSize.height-(44+20));
}
My problem is after my modal view has been presented. We cannot interact with the UITableView that has been added to the view. Anyone has encounter this problem?
Seems I found my own solution
instead of setting the bounds, I set the navigationController.view.frame:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.navigationController.view.frame = CGRectMake(screenSize.width-320, 44, 320, screenSize.height-(44));
}
I have created a Page View Controller. I can load the content view controller with the array to load the Page View Controller (code below). But in the content view, the controller doesn't load the "circles" to scroll pages. What is the problem?
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"CondicionPageViewController"];
self.pageViewController.dataSource = self;
NMCondicionPageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 50);
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
You need to set your page view controller's data source and implement the method
presentationCountForPageViewController:. In that method you will return the count for the number of dots you want.
You're also probably going to want to implement
presentationIndexForPageViewController: to return the index for which dot you want highlighted.
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.