当前位置:编程学习 > wap >>

ios textfiled自动适应软键盘高度

[cpp] 
- (id)init 

    self = [super init]; 
    if (self) { 
        self.wantsFullScreenLayout = YES; 
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent; 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillShowNotification object:nil]; 
        [[NSNotificationCenter defaultCenter] 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(@"should 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 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 

 
 
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,