iOS屏幕一点点变黑

标签 ios objective-c

我正在实现一个 iOS 应用程序。并发现有时屏幕会一点点变黑。 例如,在 View Controller 中,有一个 Collection View ,一个按钮,一个页面 Controller ,有时我发现 Collection View 变黑(或不可见),只显示黑色背景,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

我们在应用程序的管理器中发现了以下错误: :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

我的问题是: application:performFetchWithCompletionHandler 怎么会导致动画问题?

回答问题: 1.我确定手机不会休眠 2.源代码。对不起,项目太大了

最佳答案

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

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

还有 this answer可以帮助避免更多问题。

关于iOS屏幕一点点变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25320899/

相关文章:

ios - Swift 初始化委托(delegate)

ios - CoreData+mogenerator - 如何防止中间数据模型中的 `setValue(forKey:)` 引用最终数据模型中实体的 'human' 类?

ios - iOS 中的富文本编辑器

ios - 在 Objective-C 中获取当天的进度

objective-c - Mac OS X 应用程序通过 wi-fi 远程控制相机

ios - 在 Xcode 8 中工作时 Storyboard变得困惑

ios - Iphone简历上的闪屏

ios - 为 iOS 构建时,开发团队没有出现错误

objective-c - 基于 NSStrings 的 NSTableView 行高

objective-c - 我如何用一个类别来实现一个通用的协议(protocol)?