IOS疯狂基础之隐藏系统键盘

最简单的办法——设置为不可用:

   

[dateTo setUserInteractionEnabled:NO];//不弹出键盘

[dateFrom setEnabled:NO];//不弹出键盘


[[[UIApplication sharedApplication] keyWindow] endEditing:YES];


下面来讲重点:设置为不可用意味着你的各种点击事件可能也不会触发了,这个有时我们需要用到事件的触发,但不希望键盘的弹出,下面直接上码:

在触发事件的方法中增加一个消息监听就可以了

 [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];


//隐藏系统键盘

- (void)keyboardWillShow:(NSNotification *)Notification{

    UIWindow* tempWindow = [[[UIApplicationsharedApplication] windows] objectAtIndex:1];

    [tempWindow setAlpha:0];

}


你可能感兴趣的:(隐藏系统键盘)