UIAlertController的actionSheet在iOS 12.2 / 12.3上给出了约束错误

L03*_*03n 64 uialertcontroller swift5

在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 = UIAlertAction(title: "Save", style: .default)

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)

        optionMenu.addAction(deleteAction)
        optionMenu.addAction(saveAction)
        optionMenu.addAction(cancelAction)

        self.present(optionMenu, animated: true, completion: nil)
    }

}
Run Code Online (Sandbox Code Playgroud)
[LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000001b6ee0 UIView:0x7fe3b6513020.width == - 16   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000001b6ee0 UIView:0x7fe3b6513020.width == - 16   (active)>
Run Code Online (Sandbox Code Playgroud)

PS:

为了确保问题出在UIAlertController我,我删除了所有内容并更新了如下代码,但存在相同的错误。

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let optionMenu = UIAlertController(title: "Test", message: "Choose Option", preferredStyle: .actionSheet)

        let deleteAction = UIAlertAction(title: "Delete", style: .default)
        let saveAction = UIAlertAction(title: "Save", style: .default)

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)

        optionMenu.addAction(deleteAction)
        optionMenu.addAction(saveAction)
        optionMenu.addAction(cancelAction)

        self.present(optionMenu, animated: true, completion: nil)
    }

}
Run Code Online (Sandbox Code Playgroud)

And*_*nov 43

这是iOS版本中的新错误:

  • 12.2
  • 12.3
  • 12.4
  • 13.0
  • 13.1
  • 13.2
  • 13.2.3

我们唯一能做的就是向Apple提交错误报告(确实如此)。

发行后,我将尝试为新版本的iOS更新答案。

  • 它也存在于 ios 13.3 中 (11认同)
  • 在iOS 13官方版本中继续 (8认同)
  • 2020年6月22日,仍然看到这个错误。这是荒唐的。 (6认同)
  • iOS 13.2签入,问题仍然存在 (5认同)
  • 这实际上很搞笑 (5认同)
  • 该错误在iOS 13 beta 2中继续存在。 (4认同)
  • iOS 13.4 和计数... (4认同)
  • 在beta 7中继续 (3认同)
  • iOS 13.2.3 中继续 (3认同)
  • iOS 14 beta 2 仍然存在 (3认同)
  • 每次看到这个更新我都会笑 (2认同)
  • 今天我在 iOS 13.4.1 上再次注意到这个错误。有趣的是,我在去年的 WWDC 期间与苹果的一位工程师交谈过,他们说他们知道这个问题,并且应该在 iOS 13.0 中修复。好吧,也许是 iOS 14.0。 (2认同)
  • iOS 13.5也有这个问题 (2认同)
  • 仍然存在于 iOS 13.5 中 (2认同)
  • iOS 14 上仍然存在 (2认同)