我有一个安全 Controller ,当应用程序激活时触发 Touch ID。如果用户取消 Touch 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];
});
}
最佳答案
作为临时修复,请调用 becomeFirstResponder
有延迟(通过使用 dispatch_after
)但仍在主队列中。
我对这个问题的猜测是,TouchID View 位于应用程序正常窗口之外的另一个窗口上。当用户取消 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
});
关于ios - TouchID 后应用程序变为事件状态时键盘不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41014184/