Hiding the inputAccessoryView of a UIWebView

UIWebView is a workhorse of a view. You can use it to display web pages, of course, but you can also use it to display locally-generated rich content.

I was recently using  UIWebView and the  contentEditable attribute to implement a text field that allows inline images, etc. The fact that I'm using a web view, though, is an implementation detail; to the user, it should just look like any other text field.

Unfortunately,  UIWebView loves to show that little "Previous/Next" bar above the keyboard. It was useless and occupying valuable screen space, so I determined to find a way around it.

This bar is the enemy
It was actually fairly simple; a  UIWebView contains a  UIWebBrowserView, a private class that does most of the real work. I discovered via  class-dump that it also implements  -(id)inputAccessoryView, returning the bar in question. So at runtime, I create a subclass of  UIWebBrowserView and override that method to return  nil. Then I call  [self reloadInputViews], and I'm done.

I've wrapped this up into a  UIWebView category, which exposes a single property:
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;
You can find it  on gist.

Enjoy.

Note: This code has only been tested on iOS 5.1, and may not work on other versions of iOS.  I've filed rdar:// 11040111 requesting a supported way to hide this bar. For now, though, this works, and it should fail gracefully if the internal UIWebView view  hierarchy changes. If Apple ever releases a supported method for hiding this bar,please use that instead. I only resort to hackery like this when I can find no other option.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值