我有点难以根据pageViewController的高度调整ContainerView的高度。
因此在此示例中,我有两个页面:“ 黄页”,“ 紫色页”
黄页 = 120px高度
紫色页面 = 250px高度
我要做的就是在滚动到containerView上嵌入的pageViewController时自动调整高度。
希望您能提供帮助,谢谢!
这是图片。 Storyboard Image
这是我的PageViewController代码。
import UIKit
class PageViewController: UIPageViewController,UIPageViewControllerDataSource, UIPageViewControllerDelegate {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let currentIndex = pages.index(of: viewController)!
let previousIndex = abs((currentIndex - 1) % pages.count)
return pages[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let currentIndex = pages.index(of: viewController)!
let nextIndex = abs((currentIndex + 1) % pages.count)
return pages[nextIndex]
}
var pages = [UIViewController]()
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
self.dataSource = self
let page1: UIViewController! = storyboard?.instantiateViewController(withIdentifier: "page1");
let page2: UIViewController! = storyboard?.instantiateViewController(withIdentifier: "page2");
pages.append(page1)
pages.append(page2)
setViewControllers([page1], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return pages.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
override func viewDidLayoutSubviews() {
}
}
答案 0 :(得分:0)
您可以钩住容器的高度并像这样从寻呼机控制它
@IBOutlet weak var conH: NSLayoutConstraint!
//
func callMe(value:CGFloat) {
conH.constant = value
self.view.layoutIfNeeded()
}
//
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
let vc = UIApplication.shared.keyWindow?.rootViewController as! ViewController
let currentIndex = pages.index(of: previousViewControllers.first!)!
let nextIndex = abs((currentIndex + 1) % pages.count)
vc.callMe(value:nextIndex == 0 ? 100 : 200)
}
//