17

How is it possible to get rid of this annoying "undo view" shown on the iPad in iOS 9. enter image description here

Below is my own keyboard, above my accessory view. (just for testing purposes in this ugly color). Can someone please tell me how to remove it? Thanks in advance.

borchero
  • 5,562
  • 8
  • 46
  • 72
  • 1
    try this http://stackoverflow.com/questions/32606655/how-to-hide-shortcut-bar-in-ios9/32650674?noredirect=1#comment53184204_32650674 – Dheeraj Singh Sep 21 '15 at 05:15
  • In case you look for more information on this, the "undo view" is referred to as the "Shortcut" bar. It's designed so programmers can add their own shortcuts to the keyboard although I haven't seen many yet. – TenaciousJay Oct 05 '15 at 22:29

2 Answers2

32

For Swift 2.0, You can place this code in viewDidLoad and it will work like a charm.

if #available(iOS 9.0, *) {
    let item = yourTextView.inputAssistantItem
    item.leadingBarButtonGroups = []
    item.trailingBarButtonGroups = []
} else {
    // Fallback on earlier versions
}

In Swift 3.0 and 4.0

youtTextField.inputAssistantItem.leadingBarButtonGroups.removeAll()
yourTextField.inputAssistantItem.trailingBarButtonGroups.removeAll()

However the best way to use this is to subclass a UITextfield and use the above code in the init() phase. Or to create an extension Instead of using it in the viewDidLoad for each and every textField.

OverD
  • 2,612
  • 2
  • 14
  • 29
  • 1
    Just FYI, you need to call this on every UITextView or UITextField (basically anything that pops up the keyboard) as each input field has it's own UITextInputAssistantItem. – TenaciousJay Sep 29 '15 at 13:59
  • yes tenaciousJay it true, this is the only solution i have at the moment as i am still exploring IOS9 and swift 2.0 – OverD Sep 30 '15 at 13:19
  • That code snippet causes memory leak. Try it with XCode Instrument (Leak) – Allan Macatingrao Feb 01 '17 at 03:50
2

This is code in Objective-C:

if (@available(iOS 9.0, *)) {
    UITextInputAssistantItem* item = yourTextView.inputAssistantItem;
    item.leadingBarButtonGroups = @[];
    item.trailingBarButtonGroups = @[];
}
congpc87
  • 198
  • 1
  • 9