How to disable the keyboard and UITextView

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.