我正试图在我的应用程序中实现UIKeyCommand快捷方式,而且在大多数情况下,它似乎运行得很好。除了在模态视图中显示CNContactViewController之外,它似乎做了一些奇怪的事情:在CNContactViewController被取消后,键盘快捷键仍然显示在可发现的HUD中,但在整个应用程序中停止工作,即使显示视图控制器在CNContactViewController被取消后手动调用becomeFirstResponder。
这是来自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方法也是如此。按住命令键将显示可发现的HUD,并显示键盘快捷键。
这显然是联系人框架中的某种bug。只是不知道怎么解决这个问题。在dispatch_async或dispatch_after中调用dispatch_async或dispatch_after1秒不起作用。想听听一些想法。
谢谢。
发布于 2015-11-19 22:11:01
我想出的解决办法是将CNContactViewController推到导航堆栈上,而不是试图以正常方式呈现它。
https://stackoverflow.com/questions/33722827
复制相似问题