[英]hide UIMenuController displays“ paste”,“select”,“selectAll”
I am developing an app that supports IM. 我正在开发一个支持IM的应用程序。 Below is a
UITextField
, up is a UITableView
displaying historial messages in bubbles( UIView
). 下面是一个
UITextField
,一个是UITableView
,它以气泡形式显示历史消息( UIView
)。 Bubble has add longPressGesture , UIMenuController
is called by the longPressGesture. Bubble添加了
UIMenuController
, UIMenuController
由UIMenuController
调用。 My problem is when the textField is firstResponder ,the keyboad is showing, then UIMenuController
is called by longPressGesture, normally it works fine. 我的问题是,当textField是firstResponder时 ,显示了键盘,然后
UIMenuController
调用了UIMenuController
,通常它可以正常工作。 But if there is text in the textField,the menuController show more items than I expected,like "select","selectAll". 但是,如果textField中有文本,则menuController将显示比我预期更多的项目,例如“ select”,“ selectAll”。
Here belows is my code: 下面是我的代码:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(copyMenuAction:)||
action == @selector(deleteMenuAction:)||
action == @selector(resendMenuAction:)||
action == @selector(forwardMenuAction:))
{
return YES;
}
// else if (action == @selector(cut:)||
// action == @selector(copy:)||
// action == @selector(paste:))
// {
// return NO;
// }
else
return [super canPerformAction:action withSender:sender];
return NO;
}
-(BOOL) canBecomeFirstResponder{
return YES;
}
Try to add gesture recogniser only in UITableView
. 尝试仅在
UITableView
添加手势识别器。
UILongPressGestureRecognizer *longGes = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
longGes.minimumPressDuration = 2.0; //seconds
longGes.delegate = self;
[self.tableView addGestureRecognizer: longGes];
Then in the gesture handler: 然后在手势处理程序中:
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:p];
if (indexPath == nil) {
NSLog(@"long press on table view but not on a row");
}
else {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
NSLog(@"long press on table view at row %d", indexPath.row);
}
else {
NSLog(@"gestureRecognizer.state = %d", gestureRecognizer.state);
}
}
}
Hope this helps.. :) 希望这可以帮助.. :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.