iOS在uiScrollview内快速添加uipageviewcontroller

问题描述 投票:0回答:1

我想在UIscrollview中添加uipageviewController。一切都按预期添加。但是UIScrollView不会滚动。基本上,整个viewController都以横向模式加载。我正在使用UIPageViewController加载一本书,并将其添加到scrollview内,以便用户既可以滚动查看整个页面,也可以更改使用pageviewcontroller处理的页面。

这就是为什么我在scrollview中使用页面视图控制器

Output

class QuranLandController: UIViewController {

    @IBOutlet weak var quranContainer: UIView!
    @IBOutlet weak var scrollView: UIScrollView!

    // UIPageViewController
    let controller = QuranPagerController()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        addChildViewController(controller)
        controller.view.translatesAutoresizingMaskIntoConstraints = false

        quranContainer.layout(controller.view)
            .width().top().left().right().height(900)
//        containerView.addSubview(controller.view)
//
//        NSLayoutConstraint.activate([
//            controller.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
//            controller.view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
//            controller.view.topAnchor.constraint(equalTo: containerView.topAnchor),
////            quranContainer.heightAnchor.constraint(equalToConstant: 900),
//            controller.view.heightAnchor.constraint(equalTo: containerView.heightAnchor),
//            controller.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
//            ])

//        let contentRect: CGRect = quranScrollContainer.subviews.reduce(into: .zero) { rect, view in
//            rect = rect.union(view.frame)
//        }
//        quranScrollContainer.contentSize = contentRect.size

        controller.didMove(toParentViewController: self)

        //        Translator().defaultTranslation()
        for recognizer in controller.gestureRecognizers {
            if recognizer is UITapGestureRecognizer {
                recognizer.isEnabled = false
            }
        }

        let value = UIInterfaceOrientation.landscapeRight.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscapeRight
    }

    override var shouldAutorotate: Bool {
        return true
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
ios swift uiscrollview uipageviewcontroller
1个回答
0
投票

创建UIPageViewController并将UIViewControllerUIScrollView作为页面放入其中。

每个页面将滚动到底部。

© www.soinside.com 2019 - 2024. All rights reserved.