开发者

Tap in UIWebView to Hide Keyboard

I'd lik to have the same behavior in my app as Safari has. In Safari when the keyboard is visible a tap in an area outside the editing field will cause the keyboard to hide. But with a UIWebView in my own app that's not the case by default. So how can I get this behavior to my app?

I tried to add a UIGestureRecognizer but it fires never or always (depending on shouldRecognizeSimultaneouslyWithGestureRecognizer:). So I tried to override the sendEvent: in the UIWindow. But that also has the problem that I always get the tap. Even when tapping on e.g. the text that's being edited. So no text selection is possible.

--edit

I just discovered that this behaviour is not default in Safari. Only on the google search page it's this way. So there must be a JavaScript solution f开发者_如何学Pythonor this problem.


hide the keyboard when the webView is scrolled:

self.webView.scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;


Subclass the web view and override

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; Goog luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜