Generally speaking, there are so many kinds of keyboard occlusion, one is to cover the Uitextview, there is to cover Uitextfield, in general, the comparison recommended in Uiscrollview or UITableView add TextField control. But sometimes it may be inevitable.
In the Uitextview
The approach is given in the Apple's official document, where the registered observer listens for Uikeyboardwillshow and Willhide events.
-(void) Viewwillappear: (BOOL) animated
{
[super viewwillappear:animated];
[[Nsnotificationcenter Defaultcenter] addobserver:self
selector: @selector (keyboardwillshow:)
Name: Uikeyboardwillshownotification
Object:nil];
[[Nsnotificationcenter Defaultcenter] addobserver:self
selector: @selector (keyboardwillhide:)
Name: Uikeyboardwillhidenotification
Object:nil];
}
Ways to implement Customizations
-(void) Keyboardwillshow: (nsnotification *) anotification
{
nsdictionary *userinfo = [Anotification UserInfo] ;
CGRect keyboardrect = [[UserInfo Objectforkey:uikeyboardframeenduserinfokey]
cgrectvalue];
Nstimeinterval animationduration = [[UserInfo
Objectforkey:uikeyboardanimationdurationuserinfokey] DoubleValue ];
CGRect newframe = self.view.frame;
NewFrame.size.height-= keyboardRect.size.height;
[UIView beginanimations:@ "Resizetextview" context:nil];
[UIView setanimationduration:animationduration];
Self.view.frame = Newframe;
[UIView commitanimations];
}
Get the information that the keyboard displays, and then adjust the view frame according to the information, then the Willhide method is the same as above, except to change the height of the new height to + = KeyboardRect.size.height, and finally, remove the Observer:
-
(void) Viewdiddisappear: (BOOL) animated
{
[super viewdiddisappear:animated];
[[Nsnotificationcenter Defaultcenter] removeobserver:self
name:uikeyboardwillhidenotification
Object:nil ];
[[Nsnotificationcenter Defaultcenter] removeobserver:self
name:uikeyboardwillshownotification
Object:nil ];
}