UIMenuController 使用详解

来源:互联网 发布:picasa软件官方下载 编辑:程序博客网 时间:2024/05/16 04:22
<p class="p1">1. Menu所处的View必须实现 – (BOOL)canBecomeFirstResponder, 且返回YES</p><p class="p2">2. Menu所处的View必须实现 – (BOOL)canPerformAction:withSender, 并根据需求返回YES或NO</p><p class="p3">3. 使Menu所处的View成为First Responder (becomeFirstResponder)</p><p class="p3">4. 定位Menu (- setTargetRect:inView:)</p><p class="p1">5. <span class="s1">展示</span>Menu (- setMenuVisible:animated:)</p> UIMenuItem *past = [[UIMenuItem alloc]initWithTitle:@"past" action:@selector(past:)];    UIMenuItem *send = [[UIMenuItem alloc]initWithTitle:@"send" action:@selector(send:)];    UIMenuItem *gotoapp = [[UIMenuItem alloc]initWithTitle:@"gotoapp" action:@selector(gotoapp:)];    UIMenuController *menu = [UIMenuController sharedMenuController];    [menu setMenuItems:@[past,send,gotoapp]];    [menu setTargetRect:btn.frame inView:[btn superview]];    [menu setMenuVisible:YES animated:YES];

创建完UIMenuItem 后 需要实现下面两个方法

- (BOOL)canBecomeFirstResponder{    return YES;}-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{    return (action == @selector(copy:) || action == @selector(past:) || action == @selector(send:)|| action == @selector(gotoapp:));}
最后实现当选中相对应的标签时,需要执行的方法

0 0