How to remove the bottom gap of UIPageViewController

原文地址:http://stackoverflow.com/questions/19935887/how-to-remove-the-bottom-gap-of-uipageviewcontroller

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.


解决方法1://注:隐藏 UIViewPageController的字view(UIPageControl),然后调整view的大小。


28
down vote accepted

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);
share improve this answer
解决方法2:

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值