UIMenuController不显示的解决办法

- (void)pressme:(id)sender

{

    [self becomeFirstResponder]; // 用于UIMenuController显示,缺一不可


    UIMenuItem *flag = [[UIMenuItem alloc] initWithTitle:@"拷贝"action:@selector(copyContent:)];

    UIMenuItem *approve = [[UIMenuItem alloc] initWithTitle:@"@Ta"action:@selector(addFriend:)];

    UIMenuItem *deny = [[UIMenuItem alloc] initWithTitle:@"举报"action:@selector(reportContent:)];

    UIMenuController *mymenu = [UIMenuController sharedMenuController];

    [mymenu setMenuItems:[NSArray arrayWithObjects:flag, approve, deny, nil]];

    [mymenu setTargetRect:所点击的按钮Frame inView:按钮的父视图];

    YILog(@"self.btnContent.frame:%@",NSStringFromCGRect(btnContent.frame));

    YILog(@"menuItems:%@",mymenu.menuItems);

    

    [mymenu setMenuVisible:YES animated:YES];

    

//    UIWindow *window = [[UIApplication sharedApplication].delegate window];

//    if ([window isKeyWindow] == NO)

//    {

//        [window becomeKeyWindow];

//        [window makeKeyAndVisible];

//    }

}

// 用于UIMenuController显示,缺一不可

-(BOOL)canBecomeFirstResponder{

    

    return YES;

    

}

// 用于UIMenuController显示,缺一不可

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{

    

    if (action ==@selector(copyContent:) || action ==@selector(addFriend:)||

        

        action == @selector(reportContent:)){

        

        return YES;

        

    }

    

    return NO;//隐藏系统默认的菜单项

}



你可能感兴趣的:(iOS)