[英]uiView misaligning inside ViewController for iOS10, but not iOS11
I recently started using Swift and Xcode and I'm not sure why the bottom constraint for the main view in my viewcontroller
is shifted up for iOS 10 devices, whereas it works correctly on iOS11. 我最近开始使用Swift和Xcode,但我不确定为什么对iOS 10设备而言, viewcontroller
主视图的底部约束会上移,而在iOS11上却能正常工作。 I've had something similar to another application where the top view constraint was shifted down for iOS10 but I managed to fix it by overriding viewDidLayoutSubviews()
and resetting constraints for devices lower than 11. 我有一个类似于另一个应用程序的应用程序,在该应用程序中,iOS10的顶部视图约束已下移,但我设法通过覆盖viewDidLayoutSubviews()
并为低于11的设备重置约束来解决此问题。
Unfortunately, the trick doesn't seem to work this time. 不幸的是,这次欺骗似乎没有用。 If I override the bottom constraint, the bottom anchor is corrected but the top one gets pulled up and part of the view gets hidden by the navigation bar. 如果我超越了底部约束,则会更正底部锚点,但顶部锚点会被拉起,并且导航栏会隐藏部分视图。 I've been trying to find a solution via previous questions (most of them were for the top gap and I haven't managed to modify them to work for the bottom gap I'm getting) and Google, but no luck. 我一直在尝试通过以前的问题(大多数问题是最主要的问题,并且我还没有设法修改它们以解决我正在获得的最下面的问题)找到解决方案,但是没有运气。
I've attached a screenshot of the issue for clarity. 为了清楚起见,我附上了该问题的屏幕截图。 iOS11 on the left, iOS10 on the right. 左侧为iOS11,右侧为iOS10。
The override i've tried: 我尝试过的替代:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let margins = view.layoutMarginsGuide
NSLayoutConstraint.activate([
graphView.leadingAnchor.constraint(equalTo: margins.leadingAnchor),
graphView.trailingAnchor.constraint(equalTo: margins.trailingAnchor)
])
if #available(iOS 11, *) {
// safe area constraints already set
} else {
let standardSpacing: CGFloat = 0.0
NSLayoutConstraint.activate([
contentView.bottomAnchor.constraint(equalTo: bottomLayoutGuide.bottomAnchor, constant: standardSpacing)])
}
And the result: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.