iOS hide default keyboard and open custom keyboard

孤街醉人 提交于 2019-12-01 13:46:18

问题


I have an UITextview, when user taps on UITextview i need to hide the default keyboard. For that i have done,

 [myTextView setEditable: NO];

So the keyboard is not shown, here i have created an Custom View with UIButton, i need to show this UIView when the user taps on UITextView, for that i have done,

textViewDidBeginEditing{

//Here i have added UIView as subview 

}

But this method is not working because of,

[myTextView setEditable: NO];

and i need to close the UIView when user clicks the close button inside the UIView


回答1:


You should be using resignFirstResponder instead of setting the UITextView to not editable. This will hide the system keyboard.

 [myTextView resignFirstResponder];

If you want to use a different view for the keyboard then the system provided one then set inputView on the UITextView to the custom view you want to be used in place of the system keyboard.

myTextView.inputView = myCustomView;



回答2:


Perhaps using textFieldShouldBeginEditing instead of setEditable: NO works?

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
   //Here i have added UIView as subview 
   return NO;
}


来源:https://stackoverflow.com/questions/16467422/ios-hide-default-keyboard-and-open-custom-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!