为什么我不能用gestureTapRecogniser调用我的函数
我有这个简单的function,当有人点击屏幕时,函数内的代码执行,我知道函数中的代码有效,键入时我没有错误。
func reload(gestureRecognizer: UITapGestureRecognizer) { let skView = self.view! skView.presentScene(scene) }
我有这个if语句,并且所有代码都工作,除非我在某个事件发生后运行该函数。 在我尝试调用’reload()’的行中,我收到错误’使用未解析的标识符重新加载’。 你能告诉我我做错了吗? 谢谢!
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)
和reload
方法参数应该是UITapGestureRecognizer?
可选的。
func reload(gestureRecognizer: UITapGestureRecognizer?) { let skView = self.view! skView.presentScene(scene) }
另一个简短的方法是
更改使用UITapGestureRecognizer
声明的操作方法
...action: #selector(self.reload())...
意味着删除(_:)
不需要做任何事情只需调用reload()
函数。
- NSRegularExpression:用<a>标签replaceurl文本
- 是否可以设置AVPlayer允许设备在video播放过程中进入睡眠状态?
- XCode 8,有些方法消失了吗? 例如:layoutAttributesClass() – > AnyClass
- 故事板:如何将单个视图链接到多个容器视图?
- 在cocos2d中添加UIViewController
- SKSpriteNode UserInteractionEnabled不起作用
- 在UILabel / UITextView中获取单词
- 将CIFilter应用于video文件并保存
- 在canInitWithRequest的YES响应之后,NSURLProtocol不会被要求加载