Вчера я обновился до Xcode 10.2 и начал использовать Swift 5 и заметил эту ошибку при отображении моего приглашения UIAlertController
photo. Я не помню, чтобы увидеть это в Xcode 10.1
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001321e00 UIView:0x7fe1246070a0.width == - 16 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
Я читал эту проблему Как перехватить UIViewAlertForUnsatisfiableConstraints?
и смог указать на ошибку UIAlertController
(выделено красным)
![enter image description here](https://i.stack.imgur.com/Hqhry.png)
Вот мой код:
@objc private func promptPhoto() {
let prompt = UIAlertController(title: "Choose a Photo",
message: "",
preferredStyle: .actionSheet)
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
let camerAction = UIAlertAction(title: "Camera", style: .default) { _ in
guard self.isCameraAccessible() else {
self.showAlert(title: "Oops", message: "Camera is not available")
return
}
imagePicker.sourceType = .camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
}
let libraryAction = UIAlertAction(title: "Photo Library", style: .default) { _ in
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
}
let cancelAction = UIAlertAction(title: "Cancel",
style: .cancel,
handler: nil)
prompt.addAction(camerAction)
prompt.addAction(libraryAction)
prompt.addAction(cancelAction)
present(prompt, animated: true) {
// Prevent closing the prompt by touch up outside the prompt.
prompt.view.superview?.subviews[0].isUserInteractionEnabled = false
}
}
Я попытался поэкспериментировать с установкой ширины моего UIAlertController
, используя этот код внутри моего promptPhoto()
метода, но безрезультатно.
let width: NSLayoutConstraint = NSLayoutConstraint(item: prompt.view!,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: self.view.frame.width)
prompt.view.addConstraint(width)
Есть ли способ контролировать ширину UIAlertController
, чтобы я мог избавиться от своего сообщения об ошибке?
Заранее спасибо.