KISS 🇺🇦

Stop the war!

Stop the war in Ukraine! Fuck putin!

More information is at: https://war.ukraine.ua/.

There is a fund to support the Ukrainian Army: https://savelife.in.ua/en/donate/, and there is a special bank account that accepts funds in multiple currencies: https://bank.gov.ua/en/about/support-the-armed-forces. I donated to them. Please donate if you can!

Killer putin

Killer putin. Source: politico.eu.

Arrested putin

"It hasn't happened yet, but it will happen sooner or later. Beautiful photo, isn't it?" Source: twitter.

Weird delay of UIView's animation

| comments

Why a UIView’s animation may be delayed?

I had this issue recently that the animation I wanted to run would start 5 seconds later without any apparent reason:

1
2
3
4
5
6
7
8
9
- (void)barDidBaz {
    [self foo];
}

- (void)foo {
    [UIView animateWithDuration:1.0f animations:^{
        self.imageView.alpha = 0.0f;
    }];
}

It turned out that the barDidBaz method was run not on the main thread, and thus the main dispatch queue (because it was called as a delegate’s method from a socket handler in another dispatch queue), that’s why the animation was delayed. Apparently, another UI event did trigger the animation in the end.

The fix is very simple here:

1
2
3
4
5
- (void)barDidBaz {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self foo];
    });
}

We request to invoke the foo method in the main, UI dispatch queue. Another option is to wrap the call to barDidBaz into that dispatch_async(dispatch_get_main_queue(), ^{ /*…*/ }) block. BTW, do you use blocks in Objective-C? You should.

Comments