【发布时间】:2015-11-15 17:42:56
【问题描述】:
我正在尝试在我的应用程序中实现 UIKeyCommand 快捷方式,并且在大多数情况下,它似乎工作正常。除了当我在模态视图中呈现 CNContactViewController 时,它似乎做了一些奇怪的事情:关闭 CNContactViewController 后,键盘快捷键仍显示在可发现性 HUD 中,但在整个应用程序中停止工作,即使呈现视图控制器手动调用 @987654321 @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,并显示键盘快捷键。
这显然是联系人框架的某种错误。只是不确定如何解决这个问题。在 dispatch_async 或 dispatch_after 内调用 [self becomeFirstResponder] 1 秒无效。很想听听一些想法。
谢谢。
【问题讨论】:
标签: ios first-responder uiresponder cncontactviewcontroller