How to disable the keyboard and UITextView
UITextField can respond to the completion button on the keyboard to close the keyboard, while UITextView is different. Its return button or Done button performs the line feed function and cannot close the keyboard. There are two solutions: one is to capture touch End event. When a user clicks a blank area, the keyboard opened by UITextView is closed. A UIToolbar with the completion button is added (this UIToolbar is always displayed above the keyboard when it pops up, the keyboard is perfectly pasted together, and it will also be collapsed ). Of course, it is also possible to integrate these two methods for application.
The detailed code for the second method is provided below: UIToolbar * topView = [UIToolbar alloc] InitWithFrame: CGRectMake (0, 0,320, 30)]; [TopView SetBarStyle: UIBarStyleDefault];
UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc] InitWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: self Action: nil]; UIBarButtonItem * doneButton = [UIBarButtonItem alloc] InitWithTitle: @ "" style: UIBarButtonItemStyleDone target: self Action: @ selector (dismissKeyBoard)]; NSArray * buttonsArray = [NSArray ArrayWithObjects: btnSpace, doneButton, nil]; [BtnSpace release];
[DoneButton release];
[TopView setItems: buttonsArray];
[M_myUITextView setInputAccessoryView: topView];
Note: 1. dismissKeyBoard is a custom method to collapse the keyboard. You can customize the content, such as executing [m_myUITextView ResignFirstResponder]; 2. The call to the setInputAccessoryView function in the last line of code is critical. Http://ios.662p.com/thread-403-1-1.html |
Keyboard, how