V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
yellowV2ex
V2EX  ›  iDev

为什么我的app用UIAlertView点了ok之后那个背景就不消失?

  •  
  •   yellowV2ex · 2013-04-27 13:28:30 +08:00 · 3449 次点击
    这是一个创建于 4017 天前的主题,其中的信息可能已经有所发展或是发生改变。
    就是这个问题
    http://stackoverflow.com/questions/16248558/ios-6-1-2-why-the-uialertview-not-be-dismissed-background-still-on-the-screen
    上面这个也是我问的

    点了ok之后背景还在,再点屏幕,状态条就会一直闪。
    找到一片吐槽也是如此 http://mbrennek.2nw.net/2013/02/uikit-flickering.html

    搜到的都说是UI没有在主线程运行,但我已经写了好多保证他在主线程运行,`performSelectorOnMainThread` , `dispatch_async(dispatch_get_main_queue()...` 都试过了也不行。

    模拟器和真机都是这样,一点ok就留一个黑背景,然后状态条狂闪。

    一开始我以为是模拟器的bug,就没管,一直大概到开发快结束,发现真机也是这样,除了之前模拟器出问题的View,现在居然所有alert都会这样。
    就连最开始的登录界面的alert也会这样留一个背景,真是崩溃了。
    测试流程中,前端时间还不会这样。

    我尝试新建一个项目只做一个alert show,看到虽然alert消失有延迟,但最终它还是会消失的。

    所以我觉得并不是线程的问题,不知各位有没有遇到过?
    5 条回复    1970-01-01 08:00:00 +08:00
    alexrezit
        1
    alexrezit  
       2013-04-27 13:41:55 +08:00
    你的 key window 是哪个? 用了自己写的 status bar?
    yellowV2ex
        2
    yellowV2ex  
    OP
       2013-04-27 13:46:41 +08:00
    @alexrezit 经过一番测试,终于找到问题了
    我的app一进去会初始化一些东西,初试完了之后有个翻面效果,modal进去主场景。
    我发现在modal之前的alert没问题,modal进去之后的所有alert都有问题了。
    iOS 5没事,6.1.2 开始出现这个问题
    yellowV2ex
        3
    yellowV2ex  
    OP
       2013-04-27 16:54:02 +08:00
    找到真正的原因了:
    是 BWStatusBarOverlay 有一段检查是否显示然后隐掉的,有调用到 `[BWStatusBarOverlay shared]`
    因为是在下载线程里,非主线程,就这一个判断就影响了所有的 UIAlertView。

    把 `[BWStatusBarOverlay shared]` 改到主线程,问题解决。
    alexrezit
        4
    alexrezit  
       2013-04-27 17:00:06 +08:00
    = = 你看我就说可能是 status bar, 还不快感谢我~ XD
    yellowV2ex
        5
    yellowV2ex  
    OP
       2013-04-27 19:23:29 +08:00
    @alexrezit 感谢。。。
    不过真正原因还是所有UI控制的代码一定要在主线程执行,我没想到还会影响其他类的东西。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1030 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:16 · PVG 03:16 · LAX 12:16 · JFK 15:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.