14

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.

vishal dharankar
  • 7,536
  • 7
  • 57
  • 93

6 Answers6

40

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);
vishal dharankar
  • 7,536
  • 7
  • 57
  • 93
  • Thanks for the nice solution, saved me a ton of time! – Julius Jan 27 '14 at 13:28
  • 1
    Can you make the control indicator over the image itself instead of removing it? I want that because there's no indication to the user he can swipe by removing the indicator. – Nuno Gonçalves Feb 19 '15 at 05:05
  • 1
    @NunoGonçalves using above code you get access to the UIPageControl , you can make its background color to be clear and achieve it, basically you can customize the indicator once you get the access to it , which above shoes how to do. – vishal dharankar Feb 19 '15 at 07:15
  • @vishal I have tried your method to show the UIPageControl over the content, but it is not appearing no matter what. – M Abdul Sami Dec 10 '15 at 22:22
21

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.)

Michael J.
  • 511
  • 3
  • 4
  • 1
    agree, but i need those methods , i guess they are needed to supply necessary view data when you scroll. – vishal dharankar Nov 20 '13 at 12:52
  • 2
    You were right, the page control indicator does go away if you switch to the PageCurl transition style. – Julius Jan 27 '14 at 13:29
  • 4
    Removing the two methods above, also removed the dots and gap. Success! – AlexanderN Feb 16 '14 at 09:18
  • dots are disappering when u delte procedures "presentationCountForPageViewController" and "presentationIndexForPageViewController". But what if u want a scenario like this >> - we want to dots stay ! - background of dots must go away ! - scrollview inside pageviewcontrol must extent to full screen - background of pagecontrol must not clip the view ! – Add080bbA Aug 22 '14 at 12:53
  • Access the individual view and modify it the way i did check my answer for hint – vishal dharankar Aug 22 '14 at 13:08
14

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)

g.revolution
  • 11,962
  • 23
  • 81
  • 107
7

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
    }
}
Lepidopteron
  • 6,056
  • 5
  • 41
  • 53
ZaEeM ZaFaR
  • 1,508
  • 17
  • 22
0

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

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { return 0 }
deepax11
  • 199
  • 3
  • 7
0

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 :)

SMS
  • 558
  • 1
  • 9
  • 22