gpt4 book ai didi

ios - 我可以在 Swift 中使用带括号的选择器吗?

转载 作者:搜寻专家 更新时间:2023-10-31 22:30:17 24 4
gpt4 key购买 nike

我想知道如何在 Swift 3 中使用 Selector,包括 func 所需的括号中的值。

let fireRecogniser = UISwipeGestureRecognizer(target: self, action: Selector(("shootShot")))

^ 那是我拥有的识别器,但是方法“shootShot”有一个用于 Element 的参数,它是我拥有的一个 enum

这里是 'shootShot' 函数:

func shootShot(type: Element) {

let shot = SKSpriteNode(imageNamed: "\(type)Shot")
shot.texture?.filteringMode = SKTextureFilteringMode.nearest

shot.position = CGPoint(x: -self.frame.width / 2 /*playerframe*/, y: -(self.frame.height / 2) + grnd.frame.height)
shot.setScale(1)

shot.physicsBody = SKPhysicsBody(circleOfRadius: (shot.frame.height / 2))
shot.physicsBody?.affectedByGravity = false
shot.physicsBody?.allowsRotation = true
shot.physicsBody?.isDynamic = true
shot.physicsBody?.restitution = 0
shot.physicsBody?.angularDamping = 0
shot.physicsBody?.linearDamping = 0
shot.physicsBody?.friction = 0
shot.physicsBody?.categoryBitMask = Contact.Shot.rawValue
shot.physicsBody?.contactTestBitMask = Contact.Enemy.rawValue

self.addChild(shot)

// THIS WILL DEPEND ON DIFFICULTY
let spin = SKAction.rotate(byAngle: 1, duration: 0.3)
shot.run(SKAction.repeatForever(spin))
let move = SKAction.moveTo(x: self.frame.width / 2, duration: 3.0)
let remove = SKAction.removeFromParent()
shot.run(SKAction.sequence([move, remove]))
}

如您所见,该方法有一个函数需要的 Element

关于如何在我的 Selector 中包含该参数的任何帮助?谢谢。 :)

最佳答案

Swift 3 中像这样输入您的选择器

let fireRecogniser = UISwipeGestureRecognizer(target: self, action: #selector(shootShot(element:)))

关于ios - 我可以在 Swift 中使用带括号的选择器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39845736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com