- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在雇用 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];
最佳答案
我找到下面的代码,[menuController setMenuVisible:NO animated:NO];应该是设置UIMenuController不可见的地方。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")]) {
UIMenuController *menuController = [UIMenuController sharedMenuController];
if ([menuController isMenuVisible]) {
[menuController setMenuVisible:NO animated:NO];
}
}
return NO;
}
函数- (void)tap:(UITapGestureRecognizer*)gesture 在-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 之后运行> 。
关于iphone - [UIMenuController sharedMenuController].isMenuVisible 在 EGOTextView 中始终为 NO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13284057/
在我的代码中,我使用了此测试 if ([UIMenuController sharedMenuController].menuVisible) { 但是,这并不总是有效。在我的情况下,如果用户双击UI
我在雇用 EGOTextView做 NSAttributedString 编辑。 UIMenuController 上有一个错误,我无法克服。如以下代码中描述的逻辑,点击EGOTextView后UIM
我正在尝试访问在 UIWebView 中远程加载的 PDF 中的字符串。由于 Apple 为 UIMenuController 项目列出了复制/定义选项,我认为这与实现 stringByEvaluat
我正在使用 UIMenuItem 在 UICollectionView 单元格长按中执行自定义操作。这与 iOS 6 完美配合,但现在我将我的应用程序转换为 iOS 7 和 Xcode 5,但它不起作
我是一名优秀的程序员,十分优秀!