• 主页
  • iOS swift在uiScrollview中添加uiScrollview控制器

iOS swift在uiScrollview中添加uiScrollview控制器

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

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

?

?

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.
    }
    */

}

转载请注明出处:http://www.jxbyjx.net/article/20230520/1078114.html