【发布时间】:2016-02-12 11:00:30
【问题描述】:
我正在使用 Xcode v7.0 中的 Swift 2.0 制作类似于 Fruit Ninja 的游戏。但是,在 touchesBegan、touchesMoved 和 touchesCancelled 覆盖函数中,我收到以下三个错误:
“'Set' 类型的值没有成员 'anyObject'”出现两次并且 “可选类型 'Set' 的值未展开;您的意思是使用“!”还是“?”?来一次。
这里是代码
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.anyObject() as UITouch
let location = touch.locationInNode(self)
activeSlicePoints.append(location)
redrawActiveSlice()
activeSliceBG.removeAllActions()
activeSliceFG.removeAllActions()
activeSliceBG.alpha = 1
activeSliceFG.alpha = 1
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.anyObject() as UITouch
let location = touch.locationInNode(self)
activeSlicePoints.append(location)
redrawActiveSlice()
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
activeSliceBG.runAction(SKAction.fadeOutWithDuration(0.25))
activeSliceFG.runAction(SKAction.fadeOutWithDuration(0.25))
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
touchesEnded(touches, withEvent: event)
}
Here is an image of on what lines the errors appear
感谢所有帮助。提前致谢。
【问题讨论】:
标签: ios swift touchesbegan touchesmoved