IOS Toggle Keyboard

Source: Internet
Author: User

1. Click the Toolbar plus button to toggle the keyboard

After switching before switching

2 to achieve the above effect 2.1 need to listen to the keyboard pop \ Hide

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) Name: Uikeyboardwillshownotification Object:nil];

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillhide:) Name: Uikeyboardwillhidenotification Object:nil];

1 /**2 * Keyboard is about to be hidden3  */4- (void) Keyboardwillhide: (Nsnotification *) Note5 {6     //1. Time required for keyboard popup7CGFloat Duration =[Note.userinfo[uikeyboardanimationdurationuserinfokey] doublevalue];8     //2. Animations9[UIView animatewithduration:duration animations:^{TenSelf.toolbar.transform =cgaffinetransformidentity; One     }]; A}
1 /**2 * Keyboard is about to pop up3  */4- (void) Keyboardwillshow: (Nsnotification *) Note5 {6     //1. Time required for keyboard popup7CGFloat Duration =[Note.userinfo[uikeyboardanimationdurationuserinfokey] doublevalue];8     //2. Animations9[UIView animatewithduration:duration animations:^{Ten         //Remove the keyboard height OneCGRect KEYBOARDF =[Note.userinfo[uikeyboardframeenduserinfokey] cgrectvalue]; ACGFloat Keyboardh =KeyboardF.size.height; -Self.toolbar.transform = Cgaffinetransformmaketranslation (0, -Keyboardh); -     }]; the}
Lazy Loading method of 2.2 toolbar
1-(Uitoolbar *) toolbar{2     if(_toolbar = =Nil) {3_toolbar =[[Uitoolbar alloc]init];4_toolbar.frame = CGRectMake (0, ScreenHeight-ktoolbarheight, ScreenWidth, ktoolbarheight);5 [Self.view Addsubview:_toolbar];6         7         //Toggle the keyboard button8UIButton *changekeybord =[UIButton Buttonwithtype:uibuttontypecontactadd];9 [_toolbar Addsubview:changekeybord];Ten  One [Changekeybord addtarget:self Action: @selector (Changekeybord) Forcontrolevents:uicontroleventtouchdown]; A     } -     return_toolbar; -}
2.3 Implementing the Changekeybord method
1- (void) Changekeybord2 {3     if(Self.mytext.inputView) { //inputview exists then the custom keyboard 4Self.mytext.inputView =Nil; //Clear the custom keyboard, then change back to the system keyboard 5}Else{ //Conversely, Inputview does not exist, it indicates that the system keyboard is currently displayed 6UIView *newkeybord =[[UIView alloc]init]; //instantiation of a new keyboard 7Newkeybord.bounds = CGRectMake (0,0, the,216);8Newkeybord.backgroundcolor =[Uicolor Yellowcolor];9Self.mytext.inputView =Newkeybord; //Assign a new keyboard to Inputview Ten     } One  A     //The following sentence can not be saved, because after switching the keyboard, only the first hidden and then eject, will bring up the new keyboard - [Self.mytext Resignfirstresponder]; -     //In order to make the keyboard switch interactive effect smoother, increase the delay, if not increase the delay, will appear: The old keyboard has not been completely hidden, the new keyboard has been ejected theDispatch_after ((uint64_t)3.0, Dispatch_get_main_queue (), ^{ - [Self.mytext Becomefirstresponder]; -     }); -      +}
2.4 Customizing a new keyboard

Not to be continued

IOS Toggle Keyboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.