CoreAnimation warning deleted thread with uncommitted CATransaction

前端 未结 3 768
深忆病人
深忆病人 2020-12-24 07:04

I am having issues with the following warning:

CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to l

3条回答
  •  情话喂你
    2020-12-24 07:25

    Your suspicions are right. If NSOperation completes before CoreAnimation is done performing, then you get a nice warning:

    *CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.*

    This can also happen under some circumstances when a block that is dispatched on a queue triggers some work from CoreAnimation and returns before the CoreAnimation finishes.

    The solution I use is simple: On a block or NSOperation that requests work from CoreAnimation, I check that the work has indeed been completed before exiting.

    To give you a proof-of-concept example, this is a block to be dispatched on a dispatch queue. In order to avoid the warning, we check that the CoreAnimation is done before exiting.

    ^{
    
       // 1. Creating a completion indicator
    
       BOOL __block animationHasCompleted = NO;
    
       // 2. Requesting core animation do do some work. Using animator for instance.
    
       [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
          [[object animator] perform-a-nice-animation];
       } completionHandler:^{
          animationHasCompleted = YES;
       }];
    
       // 3. Doing other stuff…
    
       …
    
       // 4. Waiting for core animation to complete before exiting
    
       while (animationHasCompleted == NO)
       {
           usleep(10000);
       }
    
    }
    

提交回复
热议问题