简体   繁体   English

演示过程中尝试在<**>上演示<**>。 在使用swift从一个视图控制器到另一个视图控制器执行segue的同时

[英]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()检查UIPinchGestureRecognizerstate属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试呈现 - Attempt to present <DeviceDetailViewController…while presentation is in progress. any ideas? 简单视图控制器开关导致:在演示文稿正在进行时尝试显示 - Simple view controller switch causes: Attempt to present while a presentation is in progress Swift - 警告:在演示过程中尝试在 * 上演示 * - Swift - Warning: Attempt to present * on * while a presentation is in progress 在演示或关闭过程中尝试从视图控制器(UIModalViewController)关闭 - Attempt to dismiss from view controller (UIModalViewController) while a presentation or dismiss is in progress 得到:“在进行演示或解散时尝试从视图控制器中解散” - Getting : “Attempt to dismiss from view controller while a presentation or dismiss is in progress” 在演示或解雇过程中警告尝试从视图控制器解雇 - warning attempt to dismiss from view controller while a presentation or dismiss is in progress 在演示或解雇过程中尝试从视图控制器中解除 - Attempt to dismiss from view controller while a presentation or dismiss is in progress 快速嵌套在另一个视图控制器内部的视图控制器上执行segue - Performing a segue on a view controller that is nested inside of another view controller in swift 在另一个UIAlertController中存在UIAlertController导致尝试在取消分配时尝试加载视图控制器的视图 - Present UIAlertController in another UIAlertController cause Attempting to load the view of a view controller while it is deallocating is not allowed 无法使用 segue swift 5 将数据从一个 controller 传递到另一个 - Not able to pass data from one controller to another using segue swift 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM