gpt4 book ai didi

iphone - [UIMenuController sharedMenuController].isMenuVisible 在 EGOTextView 中始终为 NO

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:18:09 25 4
gpt4 key购买 nike

我在雇用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com