首页 > 解决方案 > 具有自动布局的 SnapKit 快速

问题描述

我根据 iPhone X 版本编辑了我的应用程序。其他 iPhone 型号由于此图像的屏幕尺寸已损坏。如何编辑根据 iPhone 版本定义的值?例如,我分享一个示例代码:

registerlabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 735).isActive = true
        registerlabel.widthAnchor.constraint(equalTo: view.widthAnchor, constant: 0).isActive = true
       registerlabel.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 157).isActive = true
        registerlabel.heightAnchor.constraint(equalToConstant: 40).isActive = true

registerlabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.chipField).offset(370)
            make.right.equalTo(140)
        }

虽然 registerlabel 出现在 iPhone X 上,但这个标签复选框不会出现在 iPhone 6 上。

我根据参考设置了chipfield的位置,但没有。

图片

标签: swiftautolayout

解决方案


而不是从你那里设置你的registerLabel位置chipfield应该使用 parentView 底部。这样您就可以在任何屏幕上使用它。

 make.bottom.equalToSuperView().offset(20) //Offset from bottom

推荐阅读