-(void) Viewwillappear: (BOOL) animated{
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) Name: Uikeyboardwillshownotification Object:nil];
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillhide:) Name: Uikeyboardwillhidenotification Object:nil];
}
-(void) Viewwilldisappear: (BOOL) animated
{
[[Nsnotificationcenter Defaultcenter] removeobserver:self];
}
-(void) Keyboardwillshow: (nsnotification *) anotification {
Get the height of the keyboard
Nsdictionary *userinfo = [Anotification userInfo];
Nsvalue *avalue = [UserInfo Objectforkey:uikeyboardframeenduserinfokey];
CGRect keyboardrect = [Avalue cgrectvalue];
int height = keyboardRect.size.height;
NSLog (@ "%d", height);
Jump to a detailed view controller
[UIView animatewithduration:0.3 animations:^{
Change position
Self.tableView.contentInset = Uiedgeinsetsmake (self.tableView.contentInset.top, 0, height, 0);
}];
}
-(void) Keyboardwillhide: (nsnotification *) anotification
{
[UIView animatewithduration:0.3 animations:^{
Change position
Self.tableView.contentInset = Uiedgeinsetsmake (self.tableView.contentInset.top, 0, 0, 0);
}];
}
or change the ordinate of a frame .
For example
Keyboardwillshow:
Self.View. Frame=CGRectMake(0, [UIScreen Mainscreen].bounds. Size. Height-height,< Span style= "color: #000000;" > mainscreen< Span style= "color: #000000;" >bounds .size.Width[UIScreen mainscreen]. bounds. Size. Height -64);
Keyboardwillhide:
Self.View. Frame=CGRectMake(0, [UIScreen Mainscreen].bounds. Size. Height,[UIScreen Mainscreen].bounds. Size. width,< Span style= "color: #3d1d81;" >[uiscreen mainscreen< Span style= "color: #000000;" >bounds .size.height-64)
The
Keyboard will appear and the keyboard will hide and the view moves up and down