简体   繁体   English

从 UIPageViewController 中移除页面指示器

[英]Remove the page indicator from UIPageViewController

I am using a page view controller in an iOs app.我在 iOs 应用程序中使用页面视图控制器。 How do I remove the dots from this controller?如何从该控制器中删除点?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dontShowChecked = NO;
    self.imagesArray = @[  ..];

    self.textsArray = @[ ........
                        ];


    // Create page view controller
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WTPageController"];
    self.pageViewController.dataSource = self;

    WTDetailViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    // Change the size of page view controller
    CGFloat delta = [[PSDeviceInfo sharedInstance] is_iPhone] ? 50. : 50;

    self.pageViewController.view.frame = CGRectMake(0, 40., self.view.frame.size.width, self.view.frame.size.height - delta);
    [self.view addSubview:_pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];
}

The dots seem to add themselves automatically and are interfering with other UI elements in that area.这些点似乎会自动添加并干扰该区域中的其他 UI 元素。 How do i Remove them completely?我如何完全删除它们?

The dots are added once your UIPageViewController datasource implements the following methods:一旦您的UIPageViewController数据源实现以下方法, UIPageViewController添加点:

presentationCountForPageViewController:
presentationIndexForPageViewController:

Avoid to implement those to get rid of the UIPageControl dots.避免实现那些以摆脱 UIPageControl 点的方法。

When pages can be increased or decreased dynamically .当页面可以动态增加或减少时

So I used below method which will manually hide the component itself.所以我使用了下面的方法,它将手动隐藏组件本身。

func togglePageControl(pageCount: Int, threshold: Int = 1) {

    var hidden = true

    if pageCount > threshold {

        hidden = false

    }

    for subView in self.view.subviews {
        if subView is UIScrollView {
            subView.frame = self.view.bounds
        } else if subView is UIPageControl {
            subView.isHidden = hidden
        }
    }
}

And this should be called from这应该从

 public func presentationCount(for pageViewController: UIPageViewController) -> Int {

     togglePageControl(pageCount: pages.count)

     // or togglePageControl(pageCount: pages.count, threshold: 5)

     return pages.count
 }

The page control is only displayed if the datasource implements these methods:页面控件仅在数据源实现以下方法时才显示:

presentationCount:
presentationIndex:

As long as you implement UIPageViewControllerDataSource functions of presentationCount and presentationIndex it will appear automatically, but in my case they came from server so I didn't know how many there will be and I only wanted to hide them if it is one.只要你实现了presentationCount和presentationIndex的UIPageViewControllerDataSource函数,它就会自动出现,但在我的情况下,它们来自服务器,所以我不知道会有多少,我只想隐藏它们,如果有的话。

So just return zero on presentationCount and you are golden.所以只需在presentationCount 上返回零,你就是金子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM