tôi có một cái UIScrollView
Đúng view.topAnchor
的约束,所以它向上滚动到 iPhoneX 的顶部边缘。但是,当我将内容添加到 scrollView(例如 UIImage)并对其进行约束 scrollView.topAnchor
时,内容将插入到 safeAreaLayoutGuide 中。这似乎发生在 scrollViews 上,因为如果我取出内容并将其放在 View 中,它也会移动到屏幕边缘。
有人知道如何解决这个问题吗?
尝试在 viewDidLoad 中将 View Controller 的 automaticallyAdjustsScrollViewInsets
设置为 false (self.automaticallyAdjustsScrollViewInsets = false
)。来自文档:
The default value of this property is true, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to false if your view controller implementation manages its own scroll view inset adjustments.
gia hạn:
如前所述,automaticallyAdjustsScrollViewInsets
在 iOS 11+ 中已弃用。您可以进行版本检查并针对旧版本的 iOS 进行修复。示例:
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
} khác {
self.automaticallyAdjustsScrollViewInsets = false
}
Tôi là một lập trình viên xuất sắc, rất giỏi!