作者:wujinlin74 | 来源:互联网 | 2023-05-28 16:49
我正在实施自定义UIMenuController
并试图找出答案.我怎样才能合法地禁用"复制"和"定义"的UIMenuItems UIMenuController
的UITextfield
?Textfield不可编辑.我尝试使用以下命令禁用"复制":
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
- (IBAction)tapTextViewGesture:(id)sender {
UIMenuItem *myItem1 = [[UIMenuItem alloc] initWithTitle:@"myItem1" action:@selector(myItem1Pressed:)];
UIMenuItem *myItem2 = [[UIMenuItem alloc] initWithTitle:@"myItem2" action:@selector(myItem2Pressed:)];
UIMenuItem *myItem3 = [[UIMenuItem alloc] initWithTitle:@"myItem3" action:@selector(myItem3Pressed:)];
// Access the application's shared menu
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObjects:myItem1,myItem2,myItem3, nil]];
CGRect menuRect = CGRectMake(20, 50, 200, 0);
// Show the menu from the cursor's position
[menu setTargetRect:menuRect inView:self.view];
[menu setMenuVisible:YES animated:YES];
}
但菜单仍然显示"复制"和"定义" UIMenuItems
.如何禁用它们,只留下我的物品?
1> Adelmaer..:
最后通过子类化UITextView
(为它创建自定义类)解决了它,并刚刚添加
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
{
return NO;
}
return NO;
}
在我的自定义TextView子类的.m文件中.
之后,"复制"不再出现,有或没有[menu update]
;