2014-12-07 93 views
0

我創建了一個UIImageView,然後在ApplicationDidLaunch中爲它分配一個模糊背景圖像。 這imageview的重疊整個屏幕,並註定要覆蓋下面的視圖控制器ApplicationDidLaunch中的RemoveFromSuperView UIImageView延遲執行

UIImage *captureImage = [self captureView:tabBar.view]; 
backgroundImage.image = [captureImage applyExtraLightEffect]; 
backgroundImage.frame = [[UIScreen mainScreen] applicationFrame]; 

[tabBar.view addSubview:backgroundImage]; 

然後我要求觸摸ID,其很好地示出了。如果TouchID認證成功我想用一個漂亮的淡出動畫刪除背景圖像

[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
     localizedReason:@"Are you the device owner?" 
        reply:^(BOOL success, NSError *error) { 
         if (error) { 
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                      message:@"There was a problem verifying your identity." 
                     delegate:nil 
                   cancelButtonTitle:@"Ok" 
                   otherButtonTitles:nil]; 
          [alert show]; 
          exit(0); 
          return; 
         } 
         if (success) { 
          NSLog(@"Passcode via TOUCH ID entered OK"); 

          [UIView animateWithDuration:0.5 
              animations:^{backgroundImage.alpha = 0;} 
              completion:^(BOOL finished){[[tabBar.view viewWithTag:13] removeFromSuperview];; }]; 
          // [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
          [UIView setAnimationDelegate:self]; 
         } 

現在我的問題是,代碼被執行的時候了,但切除和backgroundImage框架需要像5-10秒,執行。它發生在我所有的iDevices上。我不明白爲什麼在撤銷超級視圖之前有一段延遲。有沒有人有任何線索?

回答

2

完成塊可能沒有在主線程上返回。如果是這種情況,那麼如果您嘗試更改視圖,則視圖將以意想不到的方式運行。嘗試將所有視圖操作代碼放入dispatch_async(dispatch_get_main_queue())塊中。

+0

謝謝你解決了我的問題! – 2014-12-07 03:40:28