2014-10-19 70 views
0

我有以下代碼片段導致與下面的堆棧跟蹤崩潰。我如何重現這次崩潰是導航出具有此代碼的視圖控制器,而它仍在加載,因爲地圖註釋是作爲網絡請求的結果添加的。崩潰與selectAnnotation:動畫:在MKMapView

我已經縮小了原因,將動畫標誌設置爲YES的selectAnnotation調用。如果我將該標誌更改爲NO,那麼崩潰不再發生。

有沒有人有任何解釋此行爲的線索。想知道發生了什麼。

在此先感謝!


- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews 
{ 
    __weak typeof(self) weakSelf = self; 

    for (MKAnnotationView *annotationView in annotationViews) { 

     CGRect endFrame = annotationView.frame; 
     annotationView.frame = CGRectOffset(endFrame, 0, -CGRectGetHeight(self.mapView.frame)); 

     void (^ animationBlock)() = ^{ 
      annotationView.frame = endFrame; 
     }; 
     void (^ completionBlock)(BOOL) = ^(BOOL finished){ 
      [self.mapView selectAnnotation:self.annotation animated:YES]; 
     }; 

     [UIView animateWithDuration:0.5 
         animations:animationBlock 
         completion:completionBlock]; 
    } 
} 

堆棧跟蹤:

Thread 0 Crashed: 

1 libobjc.A.dylib objc_msgSend + 16 

2 UIKit __125-[UIPopoverController _presentPopoverFromRect:embeddedInView:usingViewForLayoutConstraints:permittedArrowDirections:animate:]_block_invoke421 + 92 

3 UIKit -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 404 

4 UIKit -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184 

5 UIKit -[UIViewAnimationState animationDidStop:finished:] + 100 

6 QuartzCore CA::Layer::run_animation_callbacks(void*) + 292 

7 libdispatch.dylib _dispatch_client_callout + 12 

8 libdispatch.dylib _dispatch_main_queue_callback_4CF + 928 

9 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8 

10 CoreFoundation __CFRunLoopRun + 1488 

11 CoreFoundation CFRunLoopRunSpecific + 392 

12 GraphicsServices GSEventRunModal + 164 

13 UIKit UIApplicationMain + 1484 

14 main (main.m:15) 

15 libdyld.dylib start + 
+0

無關,但:調用selectAnnotation在一個循環中的所有註釋都是沒有意義的,因爲一次只能選擇一個註釋。只有最後一個註釋的選擇會被粘住。 – Anna 2014-10-19 19:02:22

回答

0

你幾乎想通了這個問題存在,它的選擇與動畫註釋,而控制器顯示標註不是最頂層的控制器。

我建議你動畫標註只有當控制器的視圖是可見的,並沒有它們的動畫,只有當它是,看看這個問題出來了可視性檢查的方便的方法:How to tell if UIViewController's view is visible