运行随机操作

时间:2016-02-07 00:06:51

标签: swift2

我会知道如何随机运行动作吗?

let action2 = SKAction.colorizeWithColor(UIColor.cyanColor(), colorBlendFactor: 1.0, duration: 3)
let action3 = SKAction.colorizeWithColor(UIColor.purpleColor(), colorBlendFactor: 1.0, duration: 3)
let action6 = SKAction.colorizeWithColor(UIColor.darkGrayColor(), colorBlendFactor: 1.0, duration: 3)
let action7 = SKAction.colorizeWithColor(UIColor.yellowColor(), colorBlendFactor: 1.0, duration: 3)
let action8 = SKAction.colorizeWithColor(UIColor.redColor(), colorBlendFactor: 0.3, duration: 3)
let action9 = SKAction.colorizeWithColor(UIColor.orangeColor(), colorBlendFactor: 1.0, duration: 3)

let round1 = (SKAction.repeatActionForever(SKAction.sequence([action2,action3,action6,action7,action8,action9])))
let round2 = (SKAction.repeatActionForever(SKAction.sequence([action9,action8,action6,action7,action3,action2])))
let round3 = (SKAction.repeatActionForever(SKAction.sequence([action3,action9,action6,action3,action2,action7])))


var colors = [round1,round2,round3]

self.scene?.runAction(arc4random_uniform(UInt32(colors.count)))

我在self.scene?.runAction(arc4random_uniform(UInt32(colors.count)))

上收到错误

1 个答案:

答案 0 :(得分:0)

class Cell: UITableViewCell {

    @IBOutlet weak var label: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        let tap1 = UITapGestureRecognizer(target: ViewController(), action:  "selectLabel:")
        label.addGestureRecognizer(tap)
    }
 }

class ViewController: UIViewController,UITableViewDataSource, UITableViewDelegate{

    fun selectLabel(gesture: UITapGestureRecognizer){
         //animate some view in custom cell
    }
 }

此代码将生成,如:

 self.scene?.runAction(arc4random_uniform(UInt32(colors.count)))

遇到了问题?

您需要一系列操作,您可以在某处放置操作,然后通过索引从中获取。

尝试

 self.scene?.runAction(4)
 self.scene?.runAction(2)