A
A
Archakov Dennis2015-09-10 00:42:39
Apple Xcode
Archakov Dennis, 2015-09-10 00:42:39

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)
    }

And the method:
func scrollViewTapped(recognizer: UIGestureRecognizer) {
        scroll.endEditing(true)
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2015-09-10
@archakov06

Somewhere add a tap handler. Best in viewDidLoad.

UITapGestureRecognizer *tp = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                         action:@selector(randomTap:)];
[self.view addGestureRecognizer:tp];

Adding a Method
- (void)randomTap:(id)sender {
    [self.view endEditing:YES];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question