Swift/iOS8:为什么页面控制指示器不显示? [英] Swift/iOS8: Why are Page Control indicators not showing?

查看:70
本文介绍了Swift/iOS8:为什么页面控制指示器不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个简单的图库视图控制器,其中该应用程序显示用户可以滚动浏览的一小部分全屏图像.我使用的UIPageViewController我认为,如果实现正确的数据源功能,应自动显示页面控制"指示器.但是我仍然看不到任何指标.

I am implementing a straightforward gallery view controller where the app displays a small range of full-screen images that the user can scroll through. I'm using UIPageViewController which I thought, should display the Page Control indicators automatically if I implement the correct datasource functions. However I still cannot see any indicators.

在我的主要 GalleryViewController 中:

class GalleryViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

var pageController: UIPageViewController?
var pageContent = NSArray()

override func viewDidLoad() {
super.viewDidLoad()
.... some code to load images into the pageContent array ....

pageController = UIPageViewController(transitionStyle:.Scroll, navigationOrientation:.Horizontal,options:nil) 
pageController?.delegate = self
pageController?.dataSource = self

... some more standard code to add the page controller to self.view etc.

var pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray()
pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
pageControl.backgroundColor = UIColor.blackColor()

pageController!.didMoveToParentViewController(self)
}

func viewControllerAtIndex(index:Int) -> ContentViewController? {
....
}

我已经实现了两种强制性协议方法viewControllerBeforeViewController和viewControllerAfterController以及用于分页的两个必需协议:presentationCountForPagesViewController和presentationIndexForPageViewController.

I have implemented the two compulsory protocol methods viewControllerBeforeViewController and viewControllerAfterController as well as the two required ones for paging, presentationCountForPagesViewController and presentationIndexForPageViewController.

我的 ContentViewController 有一个 UIImageView ,它可以填满整个屏幕.但是,即使我减小屏幕底部的尺寸,也看不到任何页面指示灯.我在这里错过了什么吗?如果我没有提供足够的信息,请告诉我.我一直在尝试重写我5年前在Objective-C中编写的我的旧应用程序-完全在iOS 8和Xcode等的Swift中进行了更改,这令人困惑.谢谢!

My ContentViewController has a UIImageView that fills the entire screen. However even when I decrease its size off the bottom of the screen, I cannot see any page indicator lights. Have I missed something here? Let me know if I have not provided enough information. I've been trying to rewrite an old app of mine that I coded in Objective-C over 5 years ago - entirely in Swift for iOS8 and Xcode etc. has changed so much, it is confusing. Thanks!

推荐答案

来自

为了显示UIPageControl,您需要实现两个可选的数据源方法.只需返回presentationCountForPageViewController的全部页面数和presentationIndexForPageViewController最初选择的索引即可

In order to show UIPageControl, you need to implement two optional datasource methods. Just return the whole number of pages for presentationCountForPageViewController and the initially selected index for presentationIndexForPageViewController

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
    return pageContent.count
}

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

这篇关于Swift/iOS8:为什么页面控制指示器不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆