Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide the toolbar above custom keyboard extension in iOS 9

New in iOS 9 on iPad, there's a toolbar (known as the Shortcut bar) placed above the keyboard that provides undo, redo, and paste buttons. It appears while using the system keyboard or third-party keyboards, but it doesn't appear above the emoji keyboard. I don't want this toolbar visible when my custom keyboard extension is in use, as my keyboard is similar to the emoji keyboard. (Note that I'm talking about a custom keyboard extension that can be used in any app, not the keyboard shown when a text field becomes first responder in your own app.) So how can one remove it?

like image 725
Jordan H Avatar asked Aug 30 '15 20:08

Jordan H


1 Answers

You can remove it using this

- (void)textFieldDidBeginEditing:(UITextField*)textField
{
    if(SYSTEM_VERSION_GREATER_THAN(@"8.4")){
        UITextInputAssistantItem* item = [textField inputAssistantItem];
        item.leadingBarButtonGroups = @[];
        item.trailingBarButtonGroups = @[];
    }
}

and of course you need to define the macro SYSTEM_VERSION_GREATER_THAN in header to check for the version since this code will crash your app on iOS 8

#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

have fun :)

like image 132
Mohamed Emad Hegab Avatar answered Oct 19 '22 13:10

Mohamed Emad Hegab