Evgeniy Kleban
Evgeniy Kleban

Reputation: 6940

CGGradient not drawing immediately

I really can't understand what's going on. I have gradient on my image view, and i want to remove it when there is no internet. When internet is back, i want to draw it again. That may sound odd, but when internet online and my block called, it (gradient) only drawn after 10-15 seconds. What kind of black magic it is? Here is the code:

[[Reachability rac_reachabilitySignal] subscribeNext:^(Reachability *reach) {
        NSLog(@"%hhd reachable internet", reach.isReachable);
        NSLog(@"%hhd reachable waflya", reach.isReachableViaWiFi);

        if (reach.isReachable && reach.isReachableViaWiFi){
            NSLog(@"prepare to insert gradient");
            [_vFooter.layer insertSublayer:self.gradient atIndex:0];
            [self.view setNeedsDisplay];
            [self.newsImage setNeedsDisplay];
        }

    }];

Details don't really matter, be sure that block is executed right after connection appeared.

Here is screen when i did breakpoint:

enter image description here

Upvotes: 0

Views: 50

Answers (1)

jtbandes
jtbandes

Reputation: 118671

Updates to any UI, including views/layers, must be performed on the main thread!

dispatch_async(dispatch_get_main_queue(), ^{
    [_vFooter.layer insertSublayer:self.gradient atIndex:0];
    // ...
});

Upvotes: 1

Related Questions