0
當UIWebView中顯示的鍵盤上的accesory項目,則在頂部(附件項目)一個小工具欄,有按鈕「完成後,上一頁,下一頁」刪除UIWebView的鍵盤
目前,我使用以下作爲一種變通方法來刪除此工具欄:
https://gist.github.com/2048571
不過,我擔心這可能不是在iOS的未來版本。有沒有更好的方法來做到這一點?
當UIWebView中顯示的鍵盤上的accesory項目,則在頂部(附件項目)一個小工具欄,有按鈕「完成後,上一頁,下一頁」刪除UIWebView的鍵盤
目前,我使用以下作爲一種變通方法來刪除此工具欄:
https://gist.github.com/2048571
不過,我擔心這可能不是在iOS的未來版本。有沒有更好的方法來做到這一點?
首先,聽鍵盤事件:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
時,鍵盤會顯示,刪除工具欄:
- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}
的removeBar如下:
- (void)removeBar {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix:@"<UIPeripheralHostView"]) {
for (UIView* peripheralView in [possibleFormView subviews]) {
// hides the backdrop (iOS 7)
if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) {
//skip the keyboard background....hide only the toolbar background
if ([peripheralView frame].origin.y == 0){
[[peripheralView layer] setOpacity:0.0];
}
}
// hides the accessory bar
if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
// remove the extra scroll space for the form accessory bar
UIScrollView *webScroll;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
webScroll = [[self webView] scrollView];
} else {
webScroll = [[[self webView] subviews] lastObject];
}
CGRect newFrame = webScroll.frame;
newFrame.size.height += peripheralView.frame.size.height;
webScroll.frame = newFrame;
// remove the form accessory bar
[peripheralView removeFromSuperview];
}
// hides the thin grey line used to adorn the bar (iOS 6)
if ([[peripheralView description] hasPrefix:@"<UIImageView"]) {
[[peripheralView layer] setOpacity:0.0];
}
}
}
}
}
參考:https://github.com/don/KeyboardToolbarRemover/blob/master/src/ios/KeyboardToolbarRemover.m
Did你找到一個解決方案? – jAckOdE 2012-05-02 03:24:21
不幸的是,我仍然在使用這種方法。 – marklar 2012-05-03 22:39:00
我嘗試在這裏發佈的方法,但它不適用於ios 4.3。我發現這一個:http://stackoverflow.com/questions/8470984/how-to-remove-prev-next-button-from-virtual-keyboard-ios/8682238#comment13460308_8682238它適用於iOS 4.3和更高版本。 – jAckOdE 2012-05-04 04:33:13