ボタンを押すと(「タッチダウン」)、現在のコンテキストでビューコントローラーをモーダルに表示しようとしています。そのボタンを離すと(「タッチアップインサイド」)、ビューコントローラーを閉じます。
これは私のコードです:(buttonPressedは「タッチダウン」イベントで、buttonReleasedは「タッチアップインサイド」イベントです)
@IBAction func buttonPressed(_ sender: AnyObject) {
let storyboard = UIStoryboard.init(name: "Main", bundle: .main)
let anotherView = storyboard.instantiateViewController(withIdentifier: "AnotherView")
anotherView.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
anotherView.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
present(anotherView, animated: true, completion: nil)
}
@IBAction func buttonReleased(_ sender: AnyObject) {
dismiss(animated: true, completion: nil)
}
しかし、ボタンをスパムすると、別のビューが動かなくなり、そこに残されます。誰もこの問題の解決策を知っていますか? ありがとうございました。
編集:また、アニメーションを false に変更しても、これは引き続き発生するため、おそらく問題ではありません。
EDIT 2問題を解決しました。ボタンから間違ったイベントを聞いていました。ボタンをすばやく押して離すと、発生するイベントは「タッチ キャンセル」のようです。私もそれを追加し、私のコードは正常に機能するようになりました。