我目前在删除背景(屏幕底部的栏)方面存在问题,就像他们在post
中完全出现的问题一样但是,发布的解决方案都在Objective-c中。我试图把它翻译成Swift,但它没有用。
我也试图改变" UIPageControl.appearance()"清洁颜色,但它仍然没有工作。
任何人都可以提供一些提示吗?
谢谢!
我的代码在这里:
import UIKit
class TutorialViewController: UIViewController, UIPageViewControllerDataSource{
var pageViewController: UIPageViewController?
let contentImages = ["Tutorial1.png", "Tutorial2.png","Tutorial3.png"]
override func viewDidLoad() {
super.viewDidLoad()
createPageViewController()
setupPageControl()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//supporting functions
private func createPageViewController() {
let pageController = self.storyboard!.instantiateViewControllerWithIdentifier("PageController") as! UIPageViewController
pageController.dataSource = self
if contentImages.count > 0 {
let firstController = getItemController(0)!
let startingViewControllers: NSArray = [firstController]
pageController.setViewControllers(startingViewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}
pageViewController = pageController
addChildViewController(pageViewController!)
self.view.addSubview(pageViewController!.view)
pageViewController!.didMoveToParentViewController(self)
}
private func setupPageControl() {
let appearance = UIPageControl.appearance()
appearance.pageIndicatorTintColor = UIColor.grayColor()
appearance.currentPageIndicatorTintColor = UIColor.whiteColor()
appearance.backgroundColor = UIColor.clearColor()
}
// MARK: - UIPageViewControllerDataSource
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let itemController = viewController as! PageItemViewController
if itemController.itemIndex > 0 {
return getItemController(itemController.itemIndex-1)
}
return nil
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let itemController = viewController as! PageItemViewController
if itemController.itemIndex+1 < contentImages.count {
return getItemController(itemController.itemIndex+1)
}
return nil
}
private func getItemController(itemIndex: Int) -> PageItemViewController? {
if itemIndex < contentImages.count {
let pageItemController = self.storyboard!.instantiateViewControllerWithIdentifier("TutorialItemController")as! PageItemViewController
pageItemController.itemIndex = itemIndex
pageItemController.imageName = contentImages[itemIndex]
return pageItemController
}
return nil
}
// MARK: - Page Indicator
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return contentImages.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
override func prefersStatusBarHidden() -> Bool {
return true;
}
}
答案 0 :(得分:2)
尝试删除此方法
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
它很快就适合我。
答案 1 :(得分:1)
如果您检查了您提供的示例链接,我发现您可能会在实施中帮助您一些差异
1。 //我们需要通过使框架更高(+ 37)来覆盖所有控件
[[self.pageController view] setFrame:CGRectMake(0, 0, [[self view] bounds].size.width, [[self view] bounds].size.height + 37)];
- 在PageViewController中添加额外高度,以隐藏默认页面控制器底栏
//将公共控件带到前台(由于框架较高,它们被隐藏)
2。
[self.view bringSubviewToFront:self.pcDots];
诀窍是将PageControl放在底部的前景中。把UIPageControl放在UIPageController的委托方法中设置它的值
如果您需要UIPageController的完整演示实现,可以在此处查看教程:https://spin.atomicobject.com/2015/12/23/swift-uipageviewcontroller-tutorial/
在本教程结束时,如果要在故事板中的change the position of UIPageControl in the TutorialViewController
底部设置页面控件,您将获得所需的自定义UIPageController