2

我正在使用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];

}

4

2 回答 2

2

我找到了下面的代码,并且[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 之后运行

于 2012-11-08T08:29:49.117 回答
0

也许您应该尝试搜索“setMenuVisible:NO”。它也必须写在其他地方。

于 2012-11-08T08:06:23.220 回答