iOS开发问题之:UIMenuController不显示

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

设置了上面的代码还是不显示,是因为项目的其它地方设置了某个window  makeKeyAndVisible,所以在-(BOOL)canBecomeFirstResponder中要额外做一些事情才能显示menu:

- (BOOL)canBecomeFirstResponder
{
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    if ([window isKeyWindow] == NO)
    {
        [window becomeKeyWindow];
        [window makeKeyAndVisible];
    }
    return YES;
}

 

你可能感兴趣的:(iOS)