我有一个安全控制器,可在应用激活时触发Touch ID。如果用户取消触摸ID框,则会显示键盘以输入数字代码。但是我的键盘被加载(inputAccessoryView被绘制在好位置)但是看不见。我需要将应用程序背景和前景设置为键盘才能显示。
我尝试了无效的解决方案:Super slow lag/delay on initial keyboard animation of UITextField
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"User authenticated successfully, take appropriate action");
});
} else {
NSLog(@"User did not authenticate successfully, look at error and take appropriate action");
dispatch_async(dispatch_get_main_queue(), ^(void){
[self._fieldSecurity becomeFirstResponder];
});
}
}];
} else {
NSLog(@"Could not evaluate policy; look at authError and present an appropriate message to user");
dispatch_async(dispatch_get_main_queue(), ^{
[self._fieldSecurity becomeFirstResponder];
});
}
答案 0 :(得分:3)
作为临时解决方案,请延迟致电becomeFirstResponder
(使用dispatch_after
)但仍在主要队列中。
我对此问题的猜测是,TouchID视图位于应用程序正常窗口之外的另一个窗口上。当用户取消TouchID身份验证时,TouchID窗口仍然是关键窗口,因此在下面的窗口中调用UITextField
会弹出键盘出现问题。但正如我所说,这只是猜测。
使用代码更新:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void){
// Pop the keyboard
});