Xing_1102 2016-03-11 14:51 采纳率: 35.5%
浏览 2082

iOS UIMenuController 在Label上添加自定义菜单栏,会与TextFile起冲突

代码:
#import "ViewController.h"

@interface ViewController ()

@property(nonatomic,strong)UILabel *lblTitle;
@property(nonatomic,strong)UITextField *txtTitle;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.lblTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0,200, 30)];
self.lblTitle.center=self.view.center;
self.lblTitle.userInteractionEnabled=YES;
self.lblTitle.textAlignment=NSTextAlignmentCenter;
self.lblTitle.text=@"156165156161651";
[self.view addSubview:self.lblTitle];

UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
[self.lblTitle addGestureRecognizer:longPress];

self.txtTitle=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
self.txtTitle.center=CGPointMake(self.view.center.x, self.lblTitle.center.y+50);
self.txtTitle.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:self.txtTitle];


}

-(void)longPressAction:(UILongPressGestureRecognizer *)sender
{
if (sender.state==UIGestureRecognizerStateEnded)
{
    UIMenuItem *copyItem=[[UIMenuItem alloc]initWithTitle:@"复制" action:@selector(copyAction:)];
    UIMenuController *menuC=[UIMenuController sharedMenuController];
    [menuC setMenuItems:@[copyItem]];
    [menuC setTargetRect:sender.view.frame inView:self.view];
    [menuC setMenuVisible:YES animated:YES];
}
}

-(BOOL)canBecomeFirstResponder
{
return YES;
}

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action==@selector(copyAction:))
{
    return YES;
}
return NO;
}

-(void)copyAction:(UIMenuItem *)sender
{
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
pasteBoard.string=self.lblTitle.text;
NSLog(@"%@",pasteBoard.string);
}

图片说明

就是在txtfile的时候不显示自定义,只显示系统自带

  • 写回答

1条回答 默认 最新

  • 天材地宝 2016-03-14 02:44
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名