你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios textfiled自動適應軟鍵盤高度

ios textfiled自動適應軟鍵盤高度

編輯:IOS開發綜合
[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]; 

 
 
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved