私はUIAlertAction
のハンドラ(あなたはOKボタンを押した後に実行されるコード)にfalse
にdismiss(animated:completion:)
にアニメーションを設定するために処理するUIAlertController
の参照を作成するために、ISしようとしたものを第一に:
import UIKit
class ViewController: UIViewController {
var alert: UIAlertController!
@IBAction func alertViewButtonPressed(_ sender: UIButton) {
alert = UIAlertController(title: "", message: "Hello", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default) { _ in
// this code executes after you hit the OK button
self.alert.dismiss(animated: false, completion: nil)
}
alert.addAction(action)
self.present(alert, animated: true)
}
}
は残念ながらアニメーションがまだある:
![enter image description here](https://i.stack.imgur.com/h4MR9.gif)
唯一の方法は、override
dismiss(animated:completion:)
メソッドにあり、super
からfalse
の呼び出しでアニメーションフラグを設定することです。ハンドラにコードを追加する必要もなく、そのソリューションの参照を作成する必要はありません。 (注:今すぐすべての提示ビューコントローラは、そのビューコントローラでアニメーションせずに却下されます):
import UIKit
class ViewController: UIViewController {
@IBAction func alertViewButtonPressed(_ sender: UIButton) {
let alert = UIAlertController(title: "", message: "Hello", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
self.present(alert, animated: true)
}
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
// view controller which was presented modally by the view controller gets dismissed now without animation
super.dismiss(animated: false, completion: completion)
}
}
今のアラートビューは、アニメーションなしで却下されます:
![enter image description here](https://i.stack.imgur.com/x0ds5.gif)
あなたは、コードを追加することができますしてください – Ram
コードをシンプルなものにしてください –
私はボタンを無効にするのがよい回避策であると私は思っています。 –