为什么我不能用gestureTapRecogniser调用我的函数 [英] Why can't I call my function with gestureTapRecogniser

查看:76
本文介绍了为什么我不能用gestureTapRecogniser调用我的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的功能,当有人点击屏幕时,函数内部的代码会执行,我知道函数中的代码可以工作,输入时我没有错误。

I have this simple function that when someone taps the screen, the code inside the function executes, I know the code in the function works and I get no error when it is typed.

    func reload(gestureRecognizer: UITapGestureRecognizer) {
        let skView = self.view!
        skView.presentScene(scene)
    }

我有这个if语句,并且所有代码都工作,除非我在某个事件发生后运行该函数。在我尝试调用'reload()'的行中,我收到错误'使用未解析的标识符重新加载'。你能告诉我我做错了吗?谢谢!

I have this if statement, and all the code work except for when I ry to run the function after a certain event has occurred. In the line where I try and call 'reload()' I get the error 'Use of unresolved identifier reload'. Can you please tell me what I've done wrong. Thanks!

    if score[0] >= 10 {
        pauseGame()

        let textLabel = SKLabelNode(fontNamed: "Helvetica")
        textLabel.fontSize = 30
        textLabel.fontColor = SKColor.white
        textLabel.position = CGPoint(x:  20, y: 20)
        textLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center
        textLabel.text = "HELLO"
        addChild(textLabel)

        reload()

    }
    else if
        score [1] >= 10 {
        pauseGame()
        sleep(5)

        let textLabel = SKLabelNode(fontNamed: "ChalkboardSE-Bold")
        textLabel.fontSize = 30
        textLabel.fontColor = SKColor.white
        textLabel.position = CGPoint(x:  20, y: 20)
        textLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center
        textLabel.text = "HELLO"
        addChild(textLabel)

        reload()

    }


推荐答案

只需更改

reload()

reload(gestureRecognizer: nil)

重新加载方法参数应为 UITapGestureRecognizer?可选。

func reload(gestureRecognizer: UITapGestureRecognizer?) {
        let skView = self.view!
        skView.presentScene(scene)
}

另一个简短的方法

更改使用 UITapGestureRecognizer

...action: #selector(self.reload())...

表示删除(_:)无需更多操作只需调用 reload()功能。

means remove (_:) no need to do anythings more just call reload() function.

这篇关于为什么我不能用gestureTapRecogniser调用我的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆