iOS屏幕一点一点变黑

时间:2014-08-15 03:35:42

标签: ios objective-c

我正在实施一款iOS应用。并发现有时屏幕一点一点变黑。 例如,在视图控制器中,有一个集合视图,一个按钮,一个页面控制器,有时我发现集合视图变为黑色(或不可见),只显示黑色背景,1-2秒后,按钮是走了,然后整个屏幕都是黑色的。但如果我把应用程序放到后台,然后把它带回来,一切都还可以。

这是代码:


- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        NSTimeInterval timeLeft = [UIApplication sharedApplication].backgroundTimeRemaining - 1.0;
        if(timeLeft < 0)
        {
            completionHandler(UIBackgroundFetchResultNoData);
        }
        //create new thread to do something, and sleep at current thread
        ...create new threads
        [NSThread sleep:timeLeft];
        completionHandler(UIBackgroundFetchResultNewData);
    });
}
如果我多次重复以下行动,可以重现这个问题:

  1. 做点什么
  2. 将应用程序置于后台(按主页按钮)
  3. 将应用程序带回前台
  4. 重复1 - 3
  5. 我们在app的组织者中发现以下错误: :CoreAnimation:警告,删除线程与未提交的CATransaction;在环境中设置CA_DEBUG_TRANSACTIONS = 1以记录回溯。

    添加后,我得到了以下日志:

    
    Myapp[11496] : CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
        0   QuartzCore                          0x31ca6a75  + 268
        1   QuartzCore                          0x31ca6929  + 224
        2   QuartzCore                          0x31cabddb  + 86
        3   QuartzCore                          0x31cab9f7  + 150
        4   UIKit                               0x3203f919  + 344
        5   UIKit                               0x320bb11b  + 138
        6   UIKit                               0x322b0ebf  + 218
        7   UIKit                               0x322b1169  + 104
        8   UIKit                               0x322b1735  + 36
        9   Myapp                               0x002e538d __61-[AppDelegate application:performFetchWithCompletionHandler:]_block_invoke + 632
        10  libdispatch.dylib                   0x3a487d53  + 10
        11  libdispatch.dylib                   0x3a48d689  + 228
        12  libdispatch.dylib                   0x3a48d8dd  + 56
        13  libsystem_pthread.dylib             0x3a5b8c17 _pthread_wqthread + 298
        14  libsystem_pthread.dylib             0x3a5b8adc start_wqthread + 8
    

    我的问题是: 应用程序如何:performFetchWithCompletionHandler导致动画问题?

    回答问题: 我确定电话不会睡觉 2.源代码。对不起,这个项目太大了

3 个答案:

答案 0 :(得分:3)

检查您是否仅在主线程上使用UI,这应该是这种情况。

编辑 - 我见过this一个,虽然从未使用过(由Peter Steinberger撰写)。

同样this answer可以帮助避免更多问题。

答案 1 :(得分:0)

为执行你的提取而创建的线程调用一个调用来更新你的ui,当它完成它正在执行的任何任务时,它不再需要它被解除分配。 UIUpdates必须在主线程上执行,否则它们可能不会立即执行。

您是否尝试过调度到主线程,无论您在那里执行任何更新?

答案 2 :(得分:0)

很难知道你的完成处理程序正在做什么,但如果它正在更新UI,请尝试在主线程上发送它们

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        NSTimeInterval timeLeft = [UIApplication sharedApplication].backgroundTimeRemaining - 1.0;
        if(timeLeft < 0)
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                completionHandler(UIBackgroundFetchResultNoData);
            });

        }
        //create new thread to do something, and sleep at current thread
        ...create new threads
        [NSThread sleep:timeLeft];
        dispatch_async(dispatch_get_main_queue(), ^{
            completionHandler(UIBackgroundFetchResultNewData);
        });

    });
}
相关问题