1. Use uiscrollview settings to move the whole up
Place the controls on the scrollview, and then set cgpointmake (scroll. contentoffset. X, Y + 100) of scrollview when the user clicks to achieve the effect-(void) textfielddidb
-(void)textFieldDidBeginEditing:(UITextField *)textField{ UIScrollView *scroll=(UIScrollView *)self.superview; float y = 200; [scroll setContentOffset:CGPointMake(scroll.contentOffset.x, y+100) animated:YES]; }- (void)textFieldDidEndEditing:(UITextField *)textField { UIScrollView *scroll = (UIScrollView *)self.superview; [scroll setContentOffset:CGPointMake(scroll.contentOffset.x, 0) animated:YES]; return;}
Remember that these are all controls placed on scrollview,
2. The second method is to move the parent class view up as a whole,
# Pragma mark textkeyboardheight method // first responds to the textfiled method. Because there are multiple controls, tag-(void) textfielddidbeginediting :( uitextfield *) textfield {[self slideframeup: Nil withtag: textfield. tag];}-(void) textfielddidendediting :( uitextfield *) textfield {[self slideframedown: Nil withtag: textfield. tag];} // set up or down-(void) slideframeup :( ID) Up withtag :( nsinteger) Tag {[self slideframe: Yes withtag: Tag];} -(void) slideframedown :( ID) Down withtag :( nsinteger) Tag {[self slideframe: No withtag: Tag];}-(void) slideframe :( bool) Up withtag :( nsinteger) tag {// set the int movementdistance = 1; if (TAG = 3) {movementdistance = 70;} else if (TAG = 4) {movementdistance = 100; // tweak as needed} // determine whether to move up or down. Const float movementduration = 0.3f; // tweak as needed int Movement = (up? -Movementdistance: movementdistance); // animation settings [uiview beginanimations: @ "anim" context: Nil]; [uiview Duration: Yes]; [uiview setanimationduration: movementduration]; self. frame = cgrectoffset (self. frame, 0, movement); [uiview commitanimations];}
The above is a simple method not to be blocked by the keyboard,