我正在实施自定义UIMenuController
并试图弄清楚。如何合法禁用“复制”和“定义”UIMenuItemsUIMenuController
in UITextfield
?文本字段不可编辑。我尝试使用以下方法禁用“复制”:
-(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
。我怎样才能禁用它们,只留下我的物品?
最后通过子类化解决了UITextView
(为其创建自定义类)并刚刚添加
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
{
return NO;
}
return NO;
}
我的自定义 TextView 子类的 .m 文件内部。
之后“复制”不再出现,无论有没有[menu update]
;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)