//是否可以成为第一相应
-(BOOL)canBecomeFirstResponder{
return YES;
}
//是否可以接收某些菜单的某些交互操作
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
return YES;
}
[self becomeFirstResponder]; //设置菜单显示的位置 frame设置其文职 inView设置其所在的视图 [[UIMenuController sharedMenuController] setTargetRect:frame inView:self.view]; //将菜单控件设置为可见 [UIMenuController sharedMenuController].menuVisible = YES;
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
if (action == @selector(cut:)||action == @selector(copy:)) {
return YES;
}
return NO;
}
//剪切按钮的方法 - (void)cut:(nullable id)sender NS_AVAILABLE_IOS(3_0); //复制按钮的方法 - (void)copy:(nullable id)sender NS_AVAILABLE_IOS(3_0); //粘贴按钮的方法 - (void)paste:(nullable id)sender NS_AVAILABLE_IOS(3_0); //选择按钮的方法 - (void)select:(nullable id)sender NS_AVAILABLE_IOS(3_0); //全选按钮的方法 - (void)selectAll:(nullable id)sender NS_AVAILABLE_IOS(3_0); //删除按钮的方法 - (void)delete:(nullable id)sender NS_AVAILABLE_IOS(3_2); //改变书写模式为从左向右按钮触发的方法 - (void)makeTextWritingDirectionLeftToRight:(nullable id)sender NS_AVAILABLE_IOS(5_0); //改变书写模式为从右向左按钮触发的方法 - (void)makeTextWritingDirectionRightToLeft:(nullable id)sender NS_AVAILABLE_IOS(5_0);
//替换按钮
- (void)_promptForReplace:(id)arg1{
NSLog(@"promptForReplace");
}
//简体繁体转换按钮
-(void)_transliterateChinese:(id)sender{
NSLog(@"transliterateChinese");
}
//文字风格按钮
-(void)_showTextStyleOptions:(id)sender{
NSLog(@"showTextStyleOptions");
}
//定义按钮
-(void)_define:(id)sender{
NSLog(@"define");
}
-(void)_addShortcut:(id)sender{
NSLog(@"addShortcut");
}
-(void)_accessibilitySpeak:(id)sender{
NSLog(@"accessibilitySpeak");
}
//语言选择按钮
-(void)_accessibilitySpeakLanguageSelection:(id)sender{
NSLog(@"accessibilitySpeakLanguageSelection");
}
//暂停发音按钮
-(void)_accessibilityPauseSpeaking:(id)sender{
NSLog(@"accessibilityPauseSpeaking");
}
//分享按钮
-(void)_share:(id)sender{
NSLog(@"share");
}
[self becomeFirstResponder];
UIMenuItem * item = [[UIMenuItem alloc]initWithTitle:@"自定义" action:@selector(newFunc)];
[[UIMenuController sharedMenuController] setTargetRect:[sender frame] inView:self.view];
[UIMenuController sharedMenuController].menuItems = @[item];
[UIMenuController sharedMenuController].menuVisible = YES;
-(BOOL)canBecomeFirstResponder{
return YES;
}
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
if (action == @selector(newFunc)) {
return YES;
}
return NO;
}
-(void)newFunc{
NSLog(@"自定义方法");
}
//显示的位置
@property(nonatomic) UIMenuControllerArrowDirection arrowDirection;
//枚举如下:
/*
typedef NS_ENUM(NSInteger, UIMenuControllerArrowDirection) {
//默认 基于当前屏幕状态
UIMenuControllerArrowDefault, // up or down based on screen location
//箭头在上的显示模式
UIMenuControllerArrowUp NS_ENUM_AVAILABLE_IOS(3_2),
//箭头在下的显示模式
UIMenuControllerArrowDown NS_ENUM_AVAILABLE_IOS(3_2),
//箭头在左的显示模式
UIMenuControllerArrowLeft NS_ENUM_AVAILABLE_IOS(3_2),
//箭头在右的显示模式
UIMenuControllerArrowRight NS_ENUM_AVAILABLE_IOS(3_2),
};
*/
[b]
注意点总结
[/b]要正常显示菜单,必须做到以下几点:
1. -(BOOL)canBecomeFirstResponder 必须返回YES
2. -(BOOL)canPerformAction:(SEL)action withSender:(id)sender
该函数中,要显示的菜单项(包括系统的菜单项)的方法必须返回YES
3. 在显示菜单前,必须调用:
[self becomeFirstResponder]
[menuController setMenuVisible:NO];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有