【问题标题】:UIscrollview issue with iPhone XiPhone X 的 UIscrollview 问题
【发布时间】:2020-01-29 11:45:09
【问题描述】:

我的 xib 文件中有一个水平 UIScrollview。 Scrollview 在除 iPhone X、XS 和 XR 之外的所有设备上看起来都很棒。

在 iPhone 8 上看起来不错

iPhone X

我已经尝试了所有可能的解决方案,取消选中顶部栏下方,底部栏下方,自动调整子视图大小,对我没有任何作用。 iPhone X 看起来总是一样的。滚动视图的顶部约束设置为安全区域。我在这里使用的是 xib 文件。

 if #available(iOS 11.0, *) {
        scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
    } else {
        self.automaticallyAdjustsScrollViewInsets = false
        edgesForExtendedLayout = []

        // Fallback on earlier versions
    }

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
        self.scrollView.contentSize = CGSize(width: self.lectureTable.frame.size.width , height: self.scrollView.frame.size.height)
    self.automaticallyAdjustsScrollViewInsets = false
}

请解释一下。非常感谢。

【问题讨论】:

    标签: swift cocoa-touch uiscrollview xib


    【解决方案1】:

    我自己解决了。在我的滚动视图中,我使用了 UIView。

    var hasTopNotch: Bool {
           if #available(iOS 11.0,  *) {
               return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
           }
           return false
       }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        var topbarHeight: CGFloat {
            return UIApplication.shared.statusBarFrame.size.height + (self.navigationController?.navigationBar.frame.height ?? 0.0)
        }
        if hasTopNotch{
            let window = UIApplication.shared.keyWindow
            if #available(iOS 11.0, *) {
                let topPadding = window?.safeAreaInsets.top
                self.customView.frame.size.height = UIScreen.main.bounds.height - (topbarHeight + topPadding!)
            } else {
                // Fallback on earlier versions
            }
    
        }else{
            let NavBarHeight  = self.navigationController!.navigationBar.frame.height + UIApplication.shared.statusBarFrame.height
            self.customView.frame.size.height = UIScreen.main.bounds.height - NavBarHeight
        }
    
    
        }
    

    这适用于所有设备。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 2022-01-17
      • 1970-01-01
      • 2019-01-27
      • 2018-03-07
      • 1970-01-01
      • 2019-04-08
      相关资源
      最近更新 更多