当我按下一个按钮(“Touch Down”)并且当我释放该按钮(“Touch Up Inside”)时,我试图在当前上下文中以模态方式呈现一个视图控制器,我希望视图控制器被关闭。
这是我的代码:(buttonPressed 是“Touch Down”事件,buttonReleased 是“Touch Up Inside”事件)
@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)
}
但是,如果我发送垃圾邮件按钮 anotherView 会卡住并让我留在那里。有谁知道这个问题的解决方案?谢谢你。
编辑:另外,如果我将动画更改为 false,这仍然会发生,所以这可能不是问题。
编辑 2我解决了这个问题。我只是从按钮上听错误的事件。如果您真的很快按下并释放按钮,似乎被触发的事件是“触摸取消”。我也添加了这一点,我的代码现在可以正常工作了。