我有一个动态高度的视图,我试图在运行时更改此视图高度优先级.
这是我的代码部分;
if (index == 0) {
surveyViewHeightConstraint.constant = 0;
surveyViewHeightConstraint.priority = 1000;
} else if (index == 1) {
surveyViewHeightConstraint.constant = 163;
surveyViewHeightConstraint.priority = 500;
}
Run Code Online (Sandbox Code Playgroud)
我正在用按钮动作改变索引.当我运行此代码时,我收到此错误:
*** Assertion failure in -[NSLayoutConstraint setPriority:], /SourceCache/Foundation/Foundation-1141.1/Layout.subproj/NSLayoutConstraint.m:174
Run Code Online (Sandbox Code Playgroud)
这里的错误是什么?
在iOS 12.2上。使用UIAlertController的actionSheet Xcode时,遇到此问题的人都会遇到约束错误
相同的代码在iOS 12.1上运行,没有错误
我已经在Xcode 10.2和10.1上测试了此代码
class ViewController: UIViewController {
let Click : UIButton = {
let button = UIButton(type: UIButton.ButtonType.system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("OK", for: .normal)
button.tintColor = UIColor.blue
button.addTarget(self, action: #selector(click(_:)), for: UIControl.Event.touchUpInside)
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(Click)
Click.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
Click.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
@objc func click(_ sender: UIButton) {
let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet)
let deleteAction = UIAlertAction(title: "Delete", style: .default)
let saveAction = …Run Code Online (Sandbox Code Playgroud) 每当在模拟手机中显示UIAlertController操作表时,都会收到此警告。该代码没什么花哨的。
let action1 = UIAlertAction(title: "Action 1", style: .default) { _ in }
let action2 = UIAlertAction(title: "Action 2", style: .default) { _ in }
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let alert = UIAlertController(title: "title", message: "message", preferredStyle: .actionSheet)
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(cancel)
self.present(alert, animated: true)
Run Code Online (Sandbox Code Playgroud)
我正在运行Xcode 10.2(10E125),Swift5。该约束似乎超出了我的控制范围,但是请告知我是否做错了。
