ITeye博客

监控键盘的高度

刺骨的夜 · 2015-01-12 16:05 · 键盘 · 编程语言 · Markdown

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        [self registerForKeyboardNotifications];

     }

    return self;

 

}

 

- (void) registerForKeyboardNotifications

{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (keyboardWillShow:)name: UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (keyboardWillhiden:)name: UIKeyboardWillHideNotification object:nil];

}

 

- (void) keyboardWillShow:(NSNotification *) notif

{

    

    

    NSDictionary *info = [notif userInfo];

    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGSize keyboardSize = [value CGRectValue].size;

    

    NSLog(@"keyBoard:%f", keyboardSize.height);  //216

    ///keyboardWasShown = YES;

    

    self.frame =  CGRectMake(0, self.reply_heigth - keyboardSize.height - self.frame.size.height, SCREEN_WITH, 40);

}

- (void) keyboardWillhiden:(NSNotification *) notif

{

    

    NSDictionary *info = [notif userInfo];

    

    NSValue *value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];

    CGSize keyboardSize = [value CGRectValue].size;

    NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height);

    // keyboardWasShown = NO;

    [UIView animateWithDuration:0.15 animations:^{

        self.frame =  CGRectMake(0, self.reply_heigth - keyboardSize.height - self.frame.size.height, SCREEN_WITH, 40);

    }];

 

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。