我正在使用EGOTextView进行 NSAttributedString 编辑。有一个UIMenuController
我无法克服的错误。正如以下代码中描述的逻辑,在点击 EGOTextView 后,UIMenu 将交替显示和隐藏。但事实是[UIMenuController sharedMenuController].isMenuVisible
总是会得到NO,代码[menuController setMenuVisible:NO animated:NO];
永远不会被调用。我错过了什么棘手的事情吗?感谢您的任何建议!
EGOTextView.m
- (void)tap:(UITapGestureRecognizer*)gesture {
NSLog(@"[UIMenuController sharedMenuController].isMenuVisible :%d",[UIMenuController sharedMenuController].isMenuVisible);
// It always log 0 even if the UIMenu is visible on the screen.
if (_editable && ![self isFirstResponder]) {
[self becomeFirstResponder];
return;
}
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showMenu) object:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showCorrectionMenu) object:nil];
self.correctionRange = NSMakeRange(NSNotFound, 0);
if (self.selectedRange.length>0) {
self.selectedRange = NSMakeRange(_selectedRange.location, 0);
}
NSInteger index = [self closestWhiteSpaceIndexToPoint:[gesture locationInView:self]];
if (_delegateRespondsToDidSelectURL && !_editing) {
if ([self selectedLinkAtIndex:index]) {
return;
}
}
UIMenuController *menuController = [UIMenuController sharedMenuController];
NSLog(@"menuController.menuVisible :%d", menuController.menuVisible);
if ([menuController isMenuVisible]) {
// never run into here
[menuController setMenuVisible:NO animated:NO];
} else {
if (index==self.selectedRange.location) {
[self performSelector:@selector(showMenu) withObject:nil afterDelay:0.35f];
} else {
if (_editing) {
[self performSelector:@selector(showCorrectionMenu) withObject:nil afterDelay:0.35f];
}
}
}
[self.inputDelegate selectionWillChange:self];
self.markedRange = NSMakeRange(NSNotFound, 0);
self.selectedRange = NSMakeRange(index, 0);
[self.inputDelegate selectionDidChange:self];
}