14
votes

I am using UIPageViewController to show images full screen, the UIViewController which is added to UIPageController as a sub view / child has the images being showed using ImageView. Problem is the images arent comming fullscreen, instead the pagecontrol view's donts are appearing at the bottom and that space is completely wasted. Please check the image attached.

enter image description here

Here is the code

self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];

NewsItemViewController *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 NewsItemViewController is UIViewController showing images and some text and The MainViewController implements UIPageViewControllerDataSource protocol and necessary methods in MainViewController.

I believe there has to be a way to do show the things in full screen.

*** Also the MainViewController is a part of a storyboard if that matters.

6
You should use a UIPageControl and a UIScrollView instead, then you have granular control.Woodstock
Show us some code regarding how you set up the page view controller.bilobatum
@JohnWoods there has to be a way as UIPageViewController was supposed to replace UIPageControl and ScrollView plus I want flexibility of designing the view in xib editor which i wont get in you mentioned approach.vishal dharankar
@bilobatum added the code please check. I am able to search the PageControl from the UIPageViewController and hide it but still that space remains there.vishal dharankar
Ok, so the code above looks good. So we can rule that out as the problem. Let's look elsewhere. Does your NewsItemViewController contain any layout code?bilobatum

6 Answers

40
votes

Finally got the solution myself I just hide the page control from UIViewPageController and then extended the size of the UIPageViewController to cover up the gap left due to absense of page control.

 NSArray *subviews = self.pageController.view.subviews;
UIPageControl *thisControl = nil;
for (int i=0; i<[subviews count]; i++) {
    if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
        thisControl = (UIPageControl *)[subviews objectAtIndex:i];
    }
}

thisControl.hidden = true;
self.pageController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+40);
21
votes

Curious. The docs say:

If both of the methods in “Supporting a Page Indicator” are implemented and the page view controller’s transition style is UIPageViewControllerTransitionStyleScroll, a page indicator is visible.

Those two methods are:

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController { 
}

Are you implementing these two data source methods? If so, perhaps if you remove them you won't have to manually remove the page control (dots)? A quick test would be to change the

UIPageViewControllerTransitionStyleScroll

to

UIPageViewControllerTransitionStylePageCurl

and see if the page control indicator dots go away. (After commenting out your hide method, of course.)

14
votes

UIPageViewController dots are only shown when you have implemented following method:

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController;

check in you code. and also returning back zero in this method will hide the dots (UIPageControl)

7
votes

I am adding for swift 2.2 compatible code

for view in self.view.subviews {
    if view.isKindOfClass(UIScrollView) {
        view.frame = UIScreen.mainScreen().bounds
    } else if view.isKindOfClass(UIPageControl) {
        view.backgroundColor = UIColor.clearColor()
    }
}

This is the Swift 4 compatible solution, embedded in viewDidLayoutSubviews

for view in self.view.subviews {
    if view.isKind(of:UIScrollView.self) {
        view.frame = UIScreen.main.bounds
    } else if view.isKind(of:UIPageControl.self) {
        view.backgroundColor = UIColor.clear
    }
}
1
votes

Swift version :). Return Zero for below implementation inside UIPageViewController subclass. func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { return 0 }

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { return 0 }
0
votes

Set your pager controller as so

self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];

And implement,this method should return any value greater than 1

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
    // The selected item reflected in the page indicator.
    return 2;
}

Now the gap at the bottom space is removed and no page control shown :)