Ios textfiled automatically adapts to the keyboard height

Source: Internet
Author: User

[Cpp]
-(Id) init
{
Self = [super init];
If (self ){
Self. wantsFullScreenLayout = YES;
[UIApplication sharedApplication]. statusBarStyle = UIStatusBarStyleBlackTranslucent;
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (keyboardWillChangeFrame :) name: UIKeyboardWillShowNotification object: nil];
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (keyboardWillChangeFrame :) name: UIKeyboardWillHideNotification object: nil];
}
Return self;
}
 
[Cpp]
-(Void) loadview
{
Titlefield. delegate = self;
}
 
[Cpp]
# Pragma mark-
# Pragma mark-textfield delete
 
-(Void) textFieldDidBeginEditing :( UITextField *) textField
{

}
 
-(Void) textFieldDidEndEditing :( UITextField *) textField
{
[Self adjustPanelsWithKeybordHeight: 0];
}
 
-(BOOL) textFieldShouldReturn :( UITextField *) textField
{
NSLog (@ "shocould return ");
[Self. sendpanel. titlefield resignFirstResponder];
Return YES;
}
 
 
-(Void) keyboardWillChangeFrame :( NSNotification *) notification
{
NSLog (@ "keyboardWillChangeFrame ");
NSValue * keyboardBoundsValue = [[notification userInfo] objectForKey: UIKeyboardFrameEndUserInfoKey];
CGRect keyboardBounds;
[KeyboardBoundsValue getValue: & keyboardBounds];
NSLog (@ "height = % f", keyboardBounds. size. height );
[Self adjustPanelsWithKeybordHeight: keyboardBounds. size. height];
}
 
-(Void) adjustPanelsWithKeybordHeight :( float) height
{
Sendpanel. frame = CGRectMake (0, 435-height, sendpanel. frame. size. width, sendpanel. frame. size. height );
Progresspanel. frame = CGRectMake (0, 400-height, progresspanel. frame. size. width, progresspanel. frame. size. height );
}
[Html]
-(Void) dealloc
{
[[Nsicationcenter center defacenter center] removeObserver: self name: UIKeyboardWillShowNotification object: nil];
[[Nsicationcenter center defacenter center] removeObserver: self name: UIKeyboardWillHideNotification object: nil];
}
 
 

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: info-contact@alibabacloud.com 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.