2016-06-20 6 views
0

루트 프레임 컨트롤러를 멋진 작은 애니메이션으로 전환하는 데 사용하는이 코드는 몇 달 동안 작동했지만이 작업은 무작위로 중단되었습니다.UIView AnimateWithDuration이 완료 블록에 도달하지 않습니다.

UIView snapshot = [self.window snapshotViewAfterScreenUpdates:YES]; 
[viewController.view addSubview:snapshot]; 
self.window.rootViewController = viewController; 
NSLog(@"check point 1"); 
[UIView animateWithDuration:0.3 animations:^{ 
    NSLog(@"check point 2"); 
    snapshot.layer.opacity = 0; 
    NSLog(@"check point 3"); 
    snapshot.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5); 
    NSLog(@"check point 4"); 
} completion:^(BOOL finished) { 
    NSLog(@"check point 5"); 
    [snapshot removeFromSuperview]; 
    NSLog(@"check point 6"); 
}]; 

나는 체크 포인트를 통해, 이러한 체크 포인트 4 트리거를 다 넣어 ..하지만 5와 6은 트리거하지 않습니다. 그렇게 나에게 이상한 이유는 실패하더라도 완성 블록이 계속 실행되어야하기 때문입니다.

새로로드되는 루트보기 컨트롤러에서 사용자의 위치 수집 권한이 필요합니다. 어쩌면 그 팝업이 나타나면이 전환점을 망칠 수 있습니까? 그것은 익숙하지 않았습니다.

답변

1

애니메이션을 적용 할 항목이 없거나 전환 부분이 소스 코드의 다른 부분에서 이미 수행되고 코드 스 니펫이 다른 스레드 (UI 스레드 제외)에서 실행되는 경우 완료 블록이 호출되지 않습니다. 따라서 단지이 문제를 해결하려면 아래의 코드 완료 블록이 트리거하지 않습니다,

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     NSLog(@"check point 1"); 
     [UIView animateWithDuration:10.3 animations:^{ 
      NSLog(@"check point 4"); 
     } completion:^(BOOL finished) { 
      NSLog(@"check point 5"); 
      [snapshot removeFromSuperview]; 
      NSLog(@"check point 6"); 
     }]; 
}); 

을 설명하기 위해

이 가
+0

큰 일

dispatch_async(dispatch_get_main_queue(), ^{ //Your code, This runs on main thread }); 
,이 코드 내에서 코드를 동봉! 덕분에 – Gukki5

+0

@ Gukki5, 다행히 도왔습니다. :) –