首页 文章

iOS UIAlertController中断动画

提问于
浏览
2

非常简单的情况 . 我有一个自定义的UIViewController用于填写表单 . 当用户点击取消按钮时,我想要弹出警报; “你确定要退出表单吗?你的编辑将不会保存” . 如果它们没问题,VC会动画然后关闭 .

我将动画放在UIAlertAction处理程序闭包中 . 然而,动画每次都会立即发生,我假设这是因为UIAlertController在它解除时(按下按钮后)动画,然后中断VC的动画 .

有任何想法吗?基本上似乎只要按下按钮就会调用处理程序;如何在UIAlertController完成解雇后调用处理程序 .

编辑:以下是一些示例代码来说明问题:

let refreshAlert = UIAlertController(title: "Delete draft?", message: "Are you sure you want to discard this draft? It will not be saved.", preferredStyle: UIAlertControllerStyle.Alert)

refreshAlert.addAction(UIAlertAction(title: "Delete", style: .Destructive, handler: { (action: UIAlertAction!) in
    self.animationInPresentionVC() // This animation occurs instantly, it seems to be interrupted by the dismissing alert controller
}))

1 回答

  • 2

    也许你可以添加一些延迟来执行你的animationInPresentionVC():

    refreshAlert.addAction(UIAlertAction(title: "Delete", style: .Destructive, handler: { (action: UIAlertAction!) in
        self.performSelector(#selector(**your animationInPresentionVC**), , withObject: nil,  afterDelay:0.3)
    }))
    

相关问题