ios - 如何在 UIPageViewController 后面添加背景视频 View ?

标签 ios swift uipageviewcontroller

我有一个登录流程,其中有一个在后台播放的视频,以及该固定视频之上的文本页面,最后一页是登录表单。

我已经成功地构建了页面滚动,但每个页面都有自己的背景,我有点迷失了如何在背景上使用循环视频固定 View ,以及在其顶部水平滚动的透明页面那个。

更新

我的 Storyboard是这样的: 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)
}
}

我不知道如何创建 subview 并将(链接)添加到我的 bootController。

最佳答案

您刚刚尝试过以下设置吗?

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

In this you add a background video view as a bottom view in view.subviews, and then you add a view of a pageViewController above it. All that you would need is to set pageViewController.view.backgroundColor = UIColor.clear and page1.view.backgroundColor = UIColor.clear, etc., to make sure that the background is visible.

UPDATE

In your case, maybe something like this will be ok:

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”。为了获得类似的效果,您将使用不同的 View Controller ,您可以在其中包含 UIPageViewController 的 View 。然后这个父 View Controller 可以成为背景,而页面 Controller 可以成为前景(因为它被添加为 viewController 的最顶层 subview )。

关于ios - 如何在 UIPageViewController 后面添加背景视频 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48611210/

相关文章:

ios - iOS 中的 Instagram Stories 多维数据集转换是如何完成的?

iOS UICalloutBar 崩溃

android - Cordova /一般 : Easiest way to develop for different screen layouts?

ios - 多个后台线程对主线程的调用可以同时发生吗?

ios - 删除 SwiftUI 表单填充

ios - 如何仅针对横向禁用 UIPageViewController 的分页?

ios - 如何从自定义函数中调用委托(delegate)函数?

ios - iOS中如何将其他App的文件复制到本App的文档目录下?

ios - 存储目标列表的预期方式

swift - 如何在 SceneKit 中使用 SCNBufferBindingBlock?