2

I have four labels. I want to disappear label1 and label2 after X time and make label3 and label4 appear.

So I use the matt's function delay and I have two problems:

  • How to make a loop with delay ? (I tried few things but they didn't work.)
  • How to make the animation smoother ? (Please check the video.)

Here is a part of my code:

    func delay(delay:Double, closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
        // by matt on https://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    // [...]
    // After 4.2sec hide lbl 1/2, show lbl3/4, after 3.7sec hide lbl3/4, show lbl 1/2, etc.

    delay(4.2) {
        cell.label1!.hidden = true
        cell.label2!.hidden = true
        cell.label3!.hidden = false
        cell.label4!.hidden = false

    }
    delay(7.9) {
        cell.label3!.hidden = true
        cell.label4!.hidden = true
        cell.label1!.hidden = false
        cell.label2!.hidden = false
    }

    delay(12.1) {
        cell.label1!.hidden = true
        cell.label2!.hidden = true
        cell.label3!.hidden = false
        cell.label4!.hidden = false

    }
    delay(15.8) {
        cell.label3!.hidden = true
        cell.label4!.hidden = true
        cell.label1!.hidden = false
        cell.label2!.hidden = false
    }
    // [...] Copy/paste and copy/paste since I can't create a loop
    delay(56.6) {
        cell.label1!.hidden = true
        cell.label2!.hidden = true
        cell.label3!.hidden = false
        cell.label4!.hidden = false

    }
    delay(60.3) {
        cell.label3!.hidden = true
        cell.label4!.hidden = true
        cell.label1!.hidden = false
        cell.label2!.hidden = false
    }
           return cell!
}

Moreover please take a look to this video : https://youtu.be/aomYcqq7UX0 Some labels don't appear in same time, some disappear for few secs : it's very laggy.

Community
  • 1
  • 1
Julian B
  • 93
  • 2
  • 7
  • I guess this concept will not work. You're modifying cells in a NSTableView while they get moved around. When your timer hits, how will you know the cell is still visible? – qwerty_so Apr 16 '15 at 19:45

0 Answers0