Как правильно обрабатывать `UIAlertController`, если исходное представление изменяется?

Я создал UIAlertController, как показано ниже:

let menu = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)

menu.popoverPresentationController?.sourceView = someView!
menu.popoverPresentationController?.sourceRect = someView!.bounds

Он работает нормально, пока я не переверну устройство. (Только для iPad, потому что для iPad UIAlertController показывает всплывающее окно в позиции, зависящей от sourceView и sourceRect)

Когда я поворачиваю устройство, положение/размер someView изменяется каким-то другим модулем. Поэтому есть некоторые предупреждения о ограничениях:

Unable to simultaneously satisfy constraints.

Хотя это просто предупреждение, я все же надеюсь узнать, как правильно обрабатывать UIAlertController при изменении исходного представления?

РЕДАКТИРОВАТЬ: Журналы предупреждений об ограничениях:

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. 
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
"<NSAutoresizingMaskLayoutConstraint:0x7fac14c672f0 UIView:0x7fac14c994c0.width == 19>",
"<NSLayoutConstraint:0x7fac14c95260 UIView:0x7fac1483b430.width == 300>",
"<NSLayoutConstraint:0x7fac124f8520 _UIAlertControllerView:0x7fac14c41cc0.width == UIView:0x7fac14c994c0.width>",
"<NSLayoutConstraint:0x7fac14c09ac0 _UIAlertControllerView:0x7fac14c41cc0.width >= UIView:0x7fac1483b430.width>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fac14c95260 UIView:0x7fac1483b430.width == 300>

person Joe Huang    schedule 17.05.2016    source источник
comment
Какие именно ограничения неверны? Не могли бы вы показать нам код, который вызывает ошибку?   -  person Sulthan    schedule 17.05.2016
comment
чего ты хочешь добиться любым путем   -  person Nischal Hada    schedule 17.05.2016
comment
@Sulthan, пожалуйста, смотрите часть EDIT   -  person Joe Huang    schedule 17.05.2016
comment
@Sulthan код - это любой стандартный код для создания UIAlertController. Я только что добавил дополнительную информацию в свой вопрос, потому что эта проблема возникает только с iPad. Для iPad UIAlertController показывает всплывающее окно, а его положение/размер основаны на sourceView и sourceRect. И когда iPad поворачивается и если исходный вид каким-то образом изменяется, как правильно справиться с этой ситуацией?   -  person Joe Huang    schedule 17.05.2016
comment
@JoeHuang В iOS 5 и iOS 6 это происходило и с всплывающими окнами, обычно нам приходилось скрывать всплывающее окно при вращении, а затем показывать его снова, когда вращение закончилось.   -  person Sulthan    schedule 17.05.2016
comment
@Султан, как ты это скрываешь? что-то вроде theController.view.hide = true подойдет? И я должен отслеживать, открыт или закрыт контроллер?   -  person Joe Huang    schedule 17.05.2016
comment
@JoeHuang Нет, мы просто отклонили всплывающее окно перед вращением и представили его снова после вращения. Мы использовали подкласс UIViewController, который отслеживал представленные всплывающие окна и события ротации.   -  person Sulthan    schedule 17.05.2016
comment
@Султан Спасибо. Если это ответ, я приму его. Похоже, это единственный способ?   -  person Joe Huang    schedule 18.05.2016


Ответы (1)


попробуйте использовать следующее. Это работает

 @IBAction func actionContinueToPay(sender: UIButton) {
        let optionMenu = UIAlertController(title: "Select payment method", message: "Select the payment method first", preferredStyle: .ActionSheet)

        let cashOnDeliveryAction = UIAlertAction(title: "Cash On delivery", style: .Default, handler: {
            (alert: UIAlertAction!) -> Void in
            // self.serviceCallSaveOrder()
            self.serviceCallSaveOrder("No Token",STATUS: self.STATUS_COD)

        })



        let walletAction = UIAlertAction(title: "Pay by Card", style: .Default, handler: {
            (alert: UIAlertAction!) -> Void in
            self.serviceCall_GetcardInfo()

        })

        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
            (alert: UIAlertAction!) -> Void in
            print("Canrcelled")
        })
        optionMenu.addAction(cashOnDeliveryAction)
        optionMenu.addAction(walletAction)

        optionMenu.addAction(cancelAction)

        self.presentViewController(optionMenu, animated: true, completion: nil)

    }
person Nischal Hada    schedule 17.05.2016