خرید بک لینک

Vote count: 0

class ViewController: UIViewController {

let manImage = UIImage(named: "man.png")

let buttons = (0..<5).map({_ in UIButton()})

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    createButtons()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func createButtons() {
    var pos = 25
    for index in 0...4 {
        delay(Double(arc4random_uniform(5)) + 5) {
            self.buttons[index].setBackgroundImage(self.manImage, forState: .Normal)
            self.buttons[index].translatesAutoresizingMaskIntoConstraints = false
            self.view.addSubview(self.buttons[index])
            self.view.addConstraint(NSLayoutConstraint(
                item: self.buttons[index],
                attribute: .Leading,
                relatedBy: .Equal,
                toItem: self.view,
                attribute: .Leading,
                multiplier: 1,
                constant: CGFloat(pos)))
            pos += 10
            }

    }
}

func delay(delay:Double, closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
}

}

I've been using a bunch of different time delay sample code from searching, but all code results in some of the buttons to be created at the same time. From the line of code

delay(Double(arc4random_uniform(5)) + 5)

does this not mean to delay at least 5 seconds between each iteration of the for loop? Why does it do this?

Thank you.

asked 19 secs ago

برچسب: how do i get home,how do i register to vote,how do i get a passport,how do i get more pokeballs,how do i play pokemon go,how do i renew my passport,how do i take a screenshot,how do i love thee,how do i get you alone,how do i get an absentee ballot, نویسنده: استخدام کار تاريخ: جمعه 9 مهر 1395 ساعت: 13:50

صفحه بندی