我正在尝试在我的应用程序中实现 UIKeyCommand 快捷方式,并且在大多数情况下,它似乎工作正常。除了当我在模态视图中呈现 CNContactViewController 时,它似乎做了一些奇怪的事情:关闭 CNContactViewController 后,键盘快捷键仍显示在可发现性 HUD 中,但在整个应用程序中停止工作,即使呈现视图控制器becomeFirstResponder
在CNContactViewController 被解雇。
这是来自 FirstViewController:
- (void) showCNContacts {
CNContact * contact = [[CNContact alloc] init];
CNContactViewController *createContact = [CNContactViewController viewControllerForNewContact: contact];
createContact.delegate = self;
createContact.allowsActions = NO;
CNContactStore *store = [[CNContactStore alloc] init];
createContact.contactStore = store;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:createContact];
navigation.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController: navigation animated:YES completion: ^{
NSLog(@"presented CNContactVC - responder = %@", [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)]);
}];
}
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact {
[viewController dismissViewControllerAnimated:YES completion:^{
[self becomeFirstResponder];
NSLog(@"after dismissing CNContactVC - responder = %@", [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)]);
}];
}
我使用私有 API 查看firstResponder
,它正确显示FirstViewController
为第一响应者。canBecomeFirstResponder
肯定是被调用的,keyCommands
方法也是如此。按住 Command 键会调出可发现性 HUD,并显示键盘快捷键。
这显然是联系人框架的某种错误。只是不确定如何解决这个问题。[self becomeFirstResponder]
在 adispatch_async
或1 秒内调用dispatch_after
无效。很想听听一些想法。
谢谢。