我创建了一个UIImageView然后我在ApplicationDidLaunch中为它提供了一个模糊的背景图像。 此imageview与整个屏幕重叠,注定要覆盖底层视图控制器
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上。我不明白为什么在删除superview之前有一个延迟。有没有人有任何线索?
答案 0 :(得分:2)
完成块可能没有在主线程上返回。如果是这种情况,那么如果您尝试更改视图,则视图将以意想不到的方式运行。尝试将所有视图操作代码放在dispatch_async(dispatch_get_main_queue())
块中。