Answer the question
In order to leave comments, you need to log in
Swift how to hide keyboard?
I can not hide the keyboard when tapping on any area. I have for different text fields, different clav styles. And on some there is no "return" - "done" button. How to deal with such a task? To hide any "ANY" keyboard when tapping on any area.
UPD:
The same for Swift: (for those who don't want to mess around with objective-c, I write the code here)
override func viewDidLoad() {
super.viewDidLoad()
var theTap = UITapGestureRecognizer(target: self, action: "scrollViewTapped:")
scroll.addGestureRecognizer(theTap)
}
func scrollViewTapped(recognizer: UIGestureRecognizer) {
scroll.endEditing(true)
}
Answer the question
In order to leave comments, you need to log in
Somewhere add a tap handler. Best in viewDidLoad.
UITapGestureRecognizer *tp = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(randomTap:)];
[self.view addGestureRecognizer:tp];
- (void)randomTap:(id)sender {
[self.view endEditing:YES];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question