ios - 演示正在进行时尝试在 <**> 上演示 <**>。使用 swift 执行从一个 View Controller 到另一个 View Controller 的 Segue 时

标签 ios iphone swift segue uipinchgesturerecognizer

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)

}

在我的 iOS 应用程序中,当在屏幕上执行捏合手势时,我想转换到不同的 View Controller 。 点击手势是在键盘区域外点击时关闭键盘

运行应用程序时,我收到一条错误消息:

“演示正在进行时尝试在<**>上演示<**>”

新的 View Controller 出现但打开了两次,时间差非常短。查了很多博客都没有找到解决办法,请帮忙!!!

最佳答案

问题是 pinchGesture 可以被多次调用。您应该向 viewController 添加一个属性,以跟踪您已经对捏合手势执行操作的事实:

var segueInProcess = false

func pinchGesture() {
    if !segueInProcess {
        self.performSegueWithIdentifier("trick1Segue", sender: self)
        segueInProcess = true
    }
}

关于ios - 演示正在进行时尝试在 <**> 上演示 <**>。使用 swift 执行从一个 View Controller 到另一个 View Controller 的 Segue 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36522373/

相关文章:

iphone - 如何在 iPhone 的 UIWebview 中禁用 lonpress?

iphone - 如何执行当前 iOS 应用程序中的 cocos2d 游戏?

swift - numberOfRowsInSection 错误

ios - Swift:无法将表达式的类型 '$T3' 转换为类型 '$T4'

ios - 如何在 Collection View 中为不同的行实现不同的列数

ios - 如果字符限制超过 80 个字符,则不会发送推送通知

ios - 是否有 ios swift 的网络连接回调?

ios - iPhone 6/6 Plus : UITableView separator flickering and different thickness

iphone - Xcode 4.2 中的空设置包

iphone - 在 iOS 中将英制转换为公制?