Ответ 1
Здесь вы можете найти несколько полезных методов для исследования:
-
textViewDidBeginEditing:
-
textViewDidEndEditing:
Кроме того, чтобы жить UITextView
, вы часто должны выполнять действие, которое вызывает [yourTextView resignFirstResponder];
UPD: краткий пример
//you may specify UITextViewDelegate protocol in .h file interface, but it better not to expose it if not necessary
@interface ExampleViewController()<UITextViewDelegate>
@end
@implementation ExampleViewController
- (void)viewDidLoad {
[super viewDidLoad];
//assuming _textView is already instantiated and added to its superview
_textView.delegate = self;
}
//it nice to separate delegate methods with pragmas but it up to your local code style policy
#pragma mark UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView {
//handle user taps text view to type text
}
- (void)textViewDidEndEditing:(UITextView *)textView {
//handle text editing finished
}
@end
Пример Swift
class TextViewEventsViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var exampleTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.exampleTextView.delegate = self
}
func textViewDidBeginEditing(_ textView: UITextView) {
print("exampleTextView: BEGIN EDIT")
}
func textViewDidEndEditing(_ textView: UITextView) {
print("exampleTextView: END EDIT")
}
}