[英]Attempting to present <**> on <**> while a presentation is in progress. While performing a segue from one view controller to another using swift
override func viewDidAppear(animated: Bool) {
view.userInteractionEnabled = true
let pinchGesture:UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: "pinchGesture")
view.addGestureRecognizer(pinchGesture)
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
view.addGestureRecognizer(tap)
}
func dismissKeyboard() {
view.endEditing(true)
}
func pinchGesture(){
self.performSegueWithIdentifier("trick1Segue", sender: self)
}
In my iOS app, i want to transition to a different view controller when a pinch gesture is performed on the screen. 在我的iOS应用中,我想在屏幕上执行捏手势时过渡到其他视图控制器。 The tap gesture is to dismiss the keyboard when tapped outside the keyboard area 轻击手势是在键盘区域之外轻按以关闭键盘
While running the app, I get an error message: 在运行应用程序时,出现错误消息:
"Attempting to present < ** > on < ** > while a presentation is in progress" “在进行演示时尝试在<**>上演示<**”
The new view controller appears but opens twice, with a very short time difference. 新的视图控制器出现,但打开两次,时间差很短。 Looked up a lot of blogs but couldn't find a solution, please help!!! 查找了很多博客,但找不到解决方案,请帮忙!!!
The problem is that pinchGesture
can be called multiple times. 问题是pinchGesture
可以被多次调用。 You should add a property to your viewController to keep track of the fact that you already have acted upon the pinch gesture: 您应该在viewController中添加一个属性,以跟踪您已经按了捏手势的事实:
var segueInProcess = false
func pinchGesture() {
if !segueInProcess {
self.performSegueWithIdentifier("trick1Segue", sender: self)
segueInProcess = true
}
}
Gesture recognizers are called multiple times with different states. 手势识别器被多次调用具有不同状态。 What you can do is check the state
property of the UIPinchGestureRecognizer
in pinchGesture()
. 您可以做的是在pinchGesture()
检查UIPinchGestureRecognizer
的state
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.