ios - 为什么我的 [UIScrollView removeFromSuperview] 崩溃了?

标签 ios ipad animation uiscrollview

崩溃日志如下。

您是否知道 [UIScrollView removeFromSuperview] 可能崩溃的任何特定原因? ScrollView 包含具有不同类型的 UIViews 的 View 层次结构。我还发现临时版本崩溃通常不是调试版本。我找不到任何理由。

相同的 View Controller 在 iPhone 中以不同的流程加载,工作正常。但在 iPad 中它崩溃了。 在 iPad 中,在容器 View Controller 中,仅加载 viewcontroler.view。

Incident Identifier: EE102239-34D1-4BE7-8B52-41F74AB26203
CrashReporter Key:   2b11ea2a01ac5618e199ffc5a1e1f321600bb6a9
Hardware Model:      iPad3,4
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2013-06-18 15:19:16.132 +0200
OS Version:      iOS 6.1.3 (10B329)
Report Version:  104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x3bab7070 prepareForMethodLookup + 20
1   libobjc.A.dylib                 0x3bab6fb2 lookUpMethod + 42
2   libobjc.A.dylib                 0x3bab6f7e _class_lookupMethodAndLoadCache3 + 14
3   libobjc.A.dylib                 0x3bab6638 objc_msgSend_uncached + 24
4   QuartzCore                      0x357f2a72 CA::Layer::contents_visibility_changed(CA::Transaction*, bool) + 50
5   QuartzCore                      0x357f29de CA::Layer::mark_visible(CA::Transaction*, bool) + 190
6   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
7   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
8   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
9   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
10  QuartzCore                      0x357f28d2 CA::Layer::update_removed_sublayer(CA::Transaction*, unsigned int) + 18
11  QuartzCore                      0x357f255a CA::Layer::remove_sublayer(CA::Transaction*, CALayer*) + 130
12  QuartzCore                      0x357f246a CA::Layer::remove_from_superlayer() + 34
13  UIKit                           0x35a6e92c -[UIView(Hierarchy) removeFromSuperview] + 144
14  UIKit                           0x35b857bc -[UIScrollView removeFromSuperview] + 60
15  MyApp           0x000bde8a -[iPadNavigationController vcAnimationDone] (iPadNavigationController.m:400)
16  UIKit                           0x35a55ab6 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 154
17  UIKit                           0x35aca8f8 -[UIViewAnimationState animationDidStop:finished:] + 44
18  QuartzCore                      0x35801304 CA::Layer::run_animation_callbacks(void*) + 204
19  libdispatch.dylib               0x3bed55d8 _dispatch_client_callout + 20
20  libdispatch.dylib               0x3bed8e40 _dispatch_main_queue_callback_4CF + 224
21  CoreFoundation                  0x33c051ac __CFRunLoopRun + 1284
22  CoreFoundation                  0x33b78238 CFRunLoopRunSpecific + 352
23  CoreFoundation                  0x33b780c4 CFRunLoopRunInMode + 100
24  GraphicsServices                0x37733336 GSEventRunModal + 70
25  UIKit                           0x35a942b4 UIApplicationMain + 1116

代码中的几行(按要求),

    previous = showing;
    showing = [ vc retain ];
    showing.view.frame = startFrameIn;
    [ container addSubview:showing.view ];

    CGContextRef context = UIGraphicsGetCurrentContext();
    [ UIView beginAnimations:nil context:context ];
    [ UIView setAnimationDelegate:self ];
    [ UIView setAnimationDidStopSelector:@selector(vcAnimationDone) ];
    [ UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
    [ UIView setAnimationDuration:0.4 ];

    previous.view.frame = endFrameOut;
    showing.view.frame = detailFrame;

    [ UIView commitAnimations ];
}

- (void) vcAnimationDone {
    if ( previous != nil ) {
        if (previous.view.superview != nil) {
            [previous.view removeFromSuperview];
        }
        [ previous release ];
        previous = nil;
    }

最佳答案

一个很可能的原因是您过度释放了 ScrollView 或其中的一个 View 。

调用 removeFromSuperview 然后释放 View 而不是简单地减少保留计数。

关于ios - 为什么我的 [UIScrollView removeFromSuperview] 崩溃了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17170274/

相关文章:

css - 旧版 iPhone/iPad 上的特定链接不是 "clickable"

css - 什么是离散动画?

ios - 如何让SKSpriteNode重新出现在它的SKScene的对面?

ios - UIButton/UIView.animate 让按钮按顺序闪烁

javascript - Mobile Safari 阻止 URL 中的 Javascript - Safari 无法运行脚本,因为不允许以这种方式使用 JavaScript

ios - 束标识符不能从当前值错误更改

ios - GPS/Glonass 可以没有数据吗?

javascript - 为不正确的类触发的动画

ios - iPhone SDK : How come the following code only animates first frame?

ios - Swift 中 VC 之间的短期内存