UIMenuController不显示的解决办法

来源:互联网 发布:网络上写小说怎么赚钱 编辑:程序博客网 时间:2024/04/28 13:51

- (void)pressme:(id)sender

{

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


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

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

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

    UIMenuController *mymenu = [UIMenuControllersharedMenuController];

    [mymenusetMenuItems:[NSArrayarrayWithObjects:flag, approve, deny, nil]];

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

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

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

    

    [mymenu setMenuVisible:YESanimated: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;

        

    }

    

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

}



1 0