更新约束问题

时间:2018-06-15 06:44:34

标签: swift autolayout

当我以编程方式更新视图中我最顶部标签的顶部约束时,更新时的标签与我的其他标签重叠,而不是在视图中将它们向下移动。

override func viewDidLoad() {
        super.viewDidLoad()
        if UIDevice().userInterfaceIdiom == .phone {
            switch UIScreen.main.nativeBounds.height {
            case 1136:
                print("iPhone 5 or 5S or 5C")
            case 1334:
                print("iPhone 6/6S/7/8")
            case 1920, 2208:
                print("iPhone 6+/6S+/7+/8+")
                self.view.layoutIfNeeded()
                for constraint in self.view.constraints {

                    if constraint.identifier == "dateLabelConstraint" {

                self.dateLabelTopConstraint.constant = 50
                           self.view.layoutIfNeeded()
                    }
                }
            case 2436:
                print("iPhone X")
            default:
                print("unknown")
            }
        }

0 个答案:

没有答案