Swift pagecontroller 故事板 UI 对象与 UIPageviewcontroller 连接
Posted
技术标签:
【中文标题】Swift pagecontroller 故事板 UI 对象与 UIPageviewcontroller 连接【英文标题】:Swift pagecontroller storyboard UI object connect with UIPageviewcontroller 【发布时间】:2018-09-06 09:39:38 【问题描述】:我已经在容器视图中完成了 pageviewcontroller 我可以使用编程来显示页面控制,但我的容器视图是通过使用情节提要完成的,所以我不知道如何在容器中心内显示页面控制器。所以,我现在使用故事板页面控制器 ui 对象拖放它如何连接我的页面视图控制器方法以及如何通过使用 pageviewcontroller 图像数组计数来移动点。
func configurePageControl()
// The total number of pages that are available is based on how many available colors we have.
//pageControl = UIPageControl(frame: CGRect(x: 0,y: UIScreen.main.bounds.maxY - 50,width: UIScreen.main.bounds.width,height: 50))
pageControl = UIPageControl(frame: CGRect(x: self.containerview.frame.size.width / 2, y: self.containerview.frame.size.height - 50,width: UIScreen.main.bounds.width,height: 50))
self.pageControl.numberOfPages = pageTitles.count
self.pageControl.currentPage = 0
self.pageControl.tintColor = UIColor.black
self.pageControl.pageIndicatorTintColor = UIColor.white
self.pageControl.currentPageIndicatorTintColor = UIColor.black
//self.containerview.addSubview(pageControl)
// MARK: Delegate functions
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
let pageContentViewController = pageViewController.viewControllers![0]
//self.pageControl.currentPage = pageTitles.index(of: pageContentViewController)!
【问题讨论】:
【参考方案1】:func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
if let viewController = pageViewController.viewControllers?[0]
guard let index = arrayVCs.index(of: viewController) else
return
//you can find index here..
self.pageControl.currentPage = index
更新
func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
if (!completed)
self.pageControl.currentPage = pageViewController.viewControllers!.first!.view.tag //
为您的视图控制器视图设置标签。
【讨论】:
我无法将“UIViewController”类型的值转换为预期的参数类型“字符串”。在这条线守卫让 index = arrayVCs.index(of: viewController) else @Pratik Sodha “UIPageControl”类型的值没有成员“currentPageIndex”@Pratik Sodha @stackflow 使用currentPage
的UIPageControl
属性。 Ans 已编辑。以上是关于Swift pagecontroller 故事板 UI 对象与 UIPageviewcontroller 连接的主要内容,如果未能解决你的问题,请参考以下文章