1

When in landscape, I would like the content of the UIPageViewController to be full screen, and I want to hide the page indicators. In portrait, I want to show the page indicators.

I know that implementing the data source methods are what make the page indicators show/not show (see https://stackoverflow.com/a/20749979/1103584), but as I stated earlier, I want to be able to selectively hide them depending on the orientation of my app.

How can I do this? I've seen it in other apps before (the graphs in App Annie) so I know it's possible. An answer where you iterate through subviews of the UIPageViewController to find an instance of UIPageControl sounds like a very hacky solution to me...there must be a more "official" way to do it.

Thanks in advance.

Community
  • 1
  • 1
DiscDev
  • 38,652
  • 20
  • 117
  • 133
  • To solve my problem for the time being, I had to create my own page indicators. This way, I can show/hide them to fit my needs. If anyone would like me to post an example of how I'm doing it, leave a comment and I will. Otherwise, a more "official" answer will be marked as correct if someone knows a built-in way to accomplish this. – DiscDev Mar 10 '14 at 16:12

2 Answers2

1

Try adding this to your code...

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];

    UIPageControl *pageControl = [UIPageControl appearance];

    if (UIInterfaceOrientationIsLandscape(orientation)) 
    {
        pageControl.alpha = 0;
    }
    else if (UIInterfaceOrientationIsPortrait(orientation)) 
    {
        pageControl.alpha = 1;
    }
}
Justin Moser
  • 2,005
  • 3
  • 22
  • 28
0x141E
  • 12,613
  • 2
  • 41
  • 54
  • I edited the code to include how the alpha value should be used. – 0x141E Apr 23 '14 at 19:52
  • I'm sorry - I forgot that I ended up solving my own problem by making my own UIPageControl look-alike, so the appearance proxy stuff didn't have any affect on my custom page control. I'm going to update your answer to reflect the proper way of setting the alpha, but this really doesn't solve my question. This just makes the UIPageControl appear to be invisible, but it is still present on the screen, which is NOT what I want. I want the view removed from the screen entirely, so that it doesn't take up any space. – DiscDev Apr 23 '14 at 19:56
  • Your question asked how to hide/show the page indicator. – 0x141E Apr 23 '14 at 20:13
  • Not to argue semantics, but the first sentence of my question is "When in landscape, I would like the content of the UIPageViewController to be full screen" -> the key is the end of the sentence, "full screen". Setting the alpha value to 0 does not accomplish this goal. I updated the title of my question to be more specific. – DiscDev Apr 23 '14 at 20:50
1

Currently, there is no way to change the default behavior of UIPageViewController's page indicator after the setViewControllers:direction:animated:completion: method is called. Hopefully, a similar method to hiding a navigation bar will be added in a future update.

Justin Moser
  • 2,005
  • 3
  • 22
  • 28