简体   繁体   English

uiView在iOS 10的ViewController内未对齐,但在iOS11上未对齐

[英]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。

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: 结果:

失败的尝试

You need to set these 4 constraints to your Main View 您需要将这4个约束设置为主视图

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iMessage iOS11(或iOS10,Mac OSX Sierra)中禁用URL链接预览 - How to Disable URL Link Previews in iMessage iOS11 (or iOS10, Mac OSX Sierra) iOS11退出后,我能否使用Xcode8 / iOS10进行构建? - Will I be able to build using Xcode8/iOS10 after iOS11 is out? UIViewPropertyAnimator 在 iOS10 和 iOS11 上反转动画的不同行为。 `isReversed` 和 `fractionComplete` 属性上的错误? - UIViewPropertyAnimator different behaviour on iOS10 and iOS11 reversing an animation. Bug on `isReversed` and `fractionComplete` properties? iOS10 UIView具有阴影的模糊效果 - iOS10 UIView blur effect with shadow iOS 10中的UICollectionView对齐单元格 - UICollectionView in iOS 10 is misaligning cells 如何设置NavigationBar与iOS11中的ViewController内容重叠 - How to set NavigationBar overlapping the ViewController content in iOS11 以编程方式使用Autolayout Constraints将UIImageView置于UIView Swift 2.3 iOS10中 - Using Autolayout Constraints programmatically to center a UIImageView inside a UIView Swift 2.3 iOS10 iOS10中的UITextField textColor更新,而不是iOS 11中的更新 - UITextField textColor updates in iOS10, not in iOS 11 iOS10中的OpenURL - OpenURL in iOS10 UILocalNotification在iOS11中不起作用 - UILocalNotification not work in iOS11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM