The development of a friend may often encounter the click on the input box to activate the keyboard caused by the input box is obscured, there are two common solutions:
1. When the keyboard appears, move the content page up appropriately
2, when the keyboard appears, floating input box to the appropriate location the author thinks the first kind of scheme is relatively simple, here only the first one, the second similar.
First, the keyboard event monitoring settings (can be written in viewdidload):
Increased monitoring, when the keyboard appears or changes when the message is received [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) Name:uikeyboardwillshownotification object:nil];//increased monitoring when the key exits when the message is received [[Nsnotificationcenter Defaultcenter] AddObserver : Self selector: @selector (keyboardwillhide:) name:uikeyboardwillhidenotification Object:nil];
Second, in the listening event two methods to handle the view of the move up and down, the distance can be based on the height of the keyboard//implementation when the keyboard appears when the height of the keyboard to calculate the size. For the input box display location
-(void) Keyboardwillshow: (nsnotification*) anotification {nsdictionary* info = [Anotification userinfo];// Kbsize is the size of the keyboard (width, height) cgsize kbsize = [[Info objectforkey:uikeyboardframeenduserinfokey] cgrectvalue].size;// Get the height of the keyboard keyboardhight=kbsize.height;//will uiscrollview on the move hashkeyboard=yes;//set the name of the animation [UIView beginanimations:@ " Animationopen "context:nil];//Set animation interval time [UIView setanimationduration:0.20];//?? Starts the next animation using the currently running state [UIView setanimationbeginsfromcurrentstate:yes];//sets the displacement of the view movement Self.view.frame = CGRectMake ( Self.view.frame.origin.x, Self.view.frame.origin.y-keyboardhight, Self.view.frame.size.width, Self.view.frame.size.height);//Set animation end [UIView commitanimations]; }//down will not repeat
Original Blog Address: http://www.cnblogs.com/iosliu/p/4425024.html
IOS prevents keyboard occlusion