关于UIMenuController的使用总结

来源:互联网 发布:ubuntu 修复win7引导 编辑:程序博客网 时间:2024/05/19 06:17

1. Menu的初始化设置

- (void)showMenuAtRect:(CGRect)rect inView:(UIView *)inView{    [self becomeFirstResponder];    UIMenuController *theMenu = [UIMenuController sharedMenuController];    [theMenu setMenuVisible:NO animated:YES];    UIMenuItem *copyItem = [[[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copyAction:)] autorelease];    [theMenu setMenuItems:[NSArray arrayWithObjects:copyItem,nil]];    [theMenu setTargetRect:rect inView:inView];    [theMenu setMenuVisible:YES animated:YES];    }


需要注意的是  

[self becomeFirstResponder];

一定不能少了
2. Menu的事件响应及显示下面两个方法不能少了,返回Yes
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{        if (action == @selector(copyAction:)) {        return YES;    }        return NO;}-(BOOL)canBecomeFirstResponder{  // 默认是NO    return YES;}





0 0
原创粉丝点击