Simple handling of Ios_8_ keyboard

Source: Internet
Author: User



  beyondviewcontroller.h//  9_ keyboard simple processing////  Created by Beyond on 14-7-25.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <span style= "font-family:arial, Helvetica, Sans-serif;" ><UIKit/UIKit.h></span> @interface beyondviewcontroller:uiviewcontroller-(ibaction) Exitkeyboard: ( UIButton *) sender; @end </uikit>


beyondviewcontroller.m//9_ Keyboard Simple handling//problems: 1, the keyboard that pops up may obscure controls on the interface, workaround: Use ScrollView, or dynamically reduce the Y value of the control (move it above) 2,toolb AR above the two button click event, has not implemented *///Created by beyond on 14-7-25.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h" @interface Beyondviewcontroller () {//Keyboard accessory toolbar Uitoolbar *_ ToolBar;}        @end @implementation beyondviewcontroller-(void) viewdidload{[Super Viewdidload]; Add a toolbar to all keyboards [self addtoolbarforkeyboard];} Add a toolbar to all keyboards-(void) addtoolbarforkeyboard{//Mainbundel load xib, the extension does not write. xib nsarray *arrayxibobjects = [[NSBundle Ma]    Inbundle] loadnibnamed:@ "Keytoolbar" Owner:nil Options:nil];    Keyboard Accessory Toolbar _toolbar = arrayxibobjects[0];    Set toolbar Nsarray *array = self.view.subviews for all text input boxes inside the Self.view; For (UIView *obj in array) {if ([obj Iskindofclass:[uitextfield class]]) {//Why to be strong, because UIView properties Inputa         Ccessoryview is readonly uitextfield *obj2 = (Uitextfield *) obj;   Obj2.inputaccessoryview = _toolbar; }}//For the 1th Uitoolbartextbutton (Previous button) in ToolBar Add click event//[[_toolbar.subviews firstobject] addtarget:self action        : @selector (Previouskeyboard:) forcontrolevents:uicontroleventtouchupinside]; Add a click event for the 2nd Uitoolbartextbutton (Next button) in ToolBar//[[_toolbar.subviews Objectatindex:2] addtarget:self action:@        Selector (nextkeyboard:) forcontrolevents:uicontroleventtouchupinside]; Add a click event for the last Uitoolbartextbutton (Finish button) in ToolBar [[_toolbar.subviews Lastobject] addtarget:self action: @selector ( Exitkeyboard:) forcontrolevents:uicontroleventtouchupinside];} Toolbar inside, click on the Previous button-(void) Previouskeyboard: (UIButton *) sender{NSLog (@ "Click on the Previous button to activate the previous input box");} Toolbar inside, click on the Next button-(void) Nextkeyboard: (UIButton *) sender{NSLog (@ "Click the Next button to activate the next input box");} Exit keyboard-(Ibaction) Exitkeyboard: (UIButton *) Sender {//mode 1:self.view all text boxes inside (including descendant controls ...)    All exit the first responder [Self.view Endediting:yes];        Return Mode 2://Traverse all the controls inside the UIView, ResigNfirstresponder/* for (int i=0; i<self.view.subviews.count; i++) {[Self.view.subviews[i] Resignf        Irstresponder];    } */Nsarray *array = self.view.subviews;        For (UIView *obj in array) {if ([obj Iskindofclass:[uitextfield class]]) {[obj resignfirstresponder]; }}///Mode 3://At the beginning of the Self.view, a full screen transparent button, the connection, as long as the screen in the blank area of the click, you can call the above Way 1, exit the keyboard} @end


Related Article

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: 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.