1

我是这个游戏的新手,所以我真的只使用过iOS 11并且最近获得了胃灼热,试图弄清楚 Apple 在iOS 10. 而且 Apple 的UIScrollView插图调整行为文档几乎专门用于iOS 11.

程序化设置:

func setView() {

    view = UIView()
    view.frame = UIScreen.main.bounds
    view.backgroundColor = UIColor.white

}

func addScrollView() {

    if #available(iOS 11.0, *) {
        scrollView.contentInsetAdjustmentBehavior = .always
    }
    scrollView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(scrollView)
    scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
    scrollView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
    scrollView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true

}

func addFirstView() {

    firstView.translatesAutoresizingMaskIntoConstraints = false
    scrollView.addSubview(firstView)
    firstView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true
    firstView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
    firstView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
    firstView.heightAnchor.constraint(equalToConstant: 50).isActive = true

}

...

func addLastView() {

    lastView.translatesAutoresizingMaskIntoConstraints = false
    scrollView.addSubview(lastView)
    lastView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true
    lastView.topAnchor.constraint(equalTo: someOtherView.bottomAnchor).isActive = true
    lastView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
    lastView.heightAnchor.constraint(equalToConstant: 100).isActive = true
    lastView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true

}

此设置在iOS 11(内容插图自动调整)中完美运行,但在iOS 10内容插图中未调整 - 第一个视图与视图的顶部锚点齐平(而不是状态栏的底部,因为它应该是)。默认情况下automaticallyAdjustsScrollViewInsetstrue如何在 中启用自动内容插入调整行为iOS 10

4

0 回答 0