如何在UIPageViewController后面添加背景视频视图?

时间:2018-02-04 17:50:33

标签: ios swift uipageviewcontroller

我有一个在后台播放视频的登录流程,以及固定视频顶部的文字页面,最后一页是登录表单。

我已经设法构建了页面滚动,但是每个页面都有自己的背景,我有点迷失,想知道如何在bg上使用循环视频修复视图,并在透明页面上水平滚动这一点。

更新

我的故事板是这样的: storyboard 我的BootViewController正在实现页面处理程序。

import UIKit

class BootViewController: UIPageViewController, UIPageViewControllerDataSource {

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    dataSource = self

    setViewControllers([UIStoryboard(name: "Boot", bundle: nil).instantiateViewController(withIdentifier: pages[0])], direction: .forward, animated: true, completion: nil)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

let pages = [
    "IntroPageOne",
    "IntroPageTwo",
    "LoginController"
]

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

    let currentViewControllerIdentifier = viewController.restorationIdentifier

    var previousViewController = pages.index(of: currentViewControllerIdentifier!)! - 1

    if previousViewController < 0 {
        previousViewController = pages.count - 1
    }

    let previousViewControllerIdentifier = pages[previousViewController]


    return UIStoryboard(name: "Boot", bundle: nil).instantiateViewController(withIdentifier: previousViewControllerIdentifier)
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

    let currentViewControllerIdentifier = viewController.restorationIdentifier

    var nextViewController = pages.index(of: currentViewControllerIdentifier!)! + 1

    if nextViewController < 0 {
        nextViewController = 0
    }

    if nextViewController >= pages.count {
        nextViewController = 0
    }

    let nextViewControllerIdentifier = pages[nextViewController]


    return UIStoryboard(name: "Boot", bundle: nil).instantiateViewController(withIdentifier: nextViewControllerIdentifier)
}
}

我迷失了如何创建子视图并添加(链接)到我的bootController。

1 个答案:

答案 0 :(得分:0)

您刚刚尝试以下设置吗?

UIViewController.view
  - backgroundVideoView
  - pageViewController.view
     - page1
     - page2
     ...

在此处,您可以在view.subviews中添加背景视频视图作为底部视图,然后在其上方添加一个view的pageViewController。您需要的只是设置pageViewController.view.backgroundColor = UIColor.clearpage1.view.backgroundColor = UIColor.clear等,以确保背景可见。

<强>更新

在你的情况下,也许这样的事情就可以了:

class BackgroundViewController: UIViewController {

    fileprivate var pageViewController: BootViewController!

    override func viewDidLoad() {
        super.viewDidLoad()

        // configure here anything with the video that you have to configure

        pageViewController = UIStoryboard(name: "Boot", bundle: nil).instantiateViewController(withIdentifier: "BootViewController") as! BootViewController
        self.view.addSubview(pageViewController.view)

        // set the frame, or use autolayout.. I will set the frame directly since it's easier here
        pageViewController.view.frame = self.view.frame
    }
}

UIPageViewController没有“backgroundView”。要获得类似的内容,您将使用不同的视图控制器,您可以在其中包含UIPageViewController的视图。然后这个父视图控制器可以成为后台,页面控制器可以成为前景(因为它被添加为viewController的最顶层子视图)。