ios 键盘弹起

#pragma mark 键盘弹起操作

- (void)keyboardWillShow:(NSNotification *)notification
{
    NSDictionary *info = notification.userInfo;
    kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    [UIView beginAnimations:@"kbmove" context:nil];
    [UIView setAnimationDelay:0.5];
    if (!iPhone5) {
        
        self.view.frame = CGRectMake(0, 0 - kbSize.height + 150, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    }else
    {
        self.view.frame = CGRectMake(0, 0 - kbSize.height + 120, SCREEN_WIDTH, SCREEN_HEIGHT);
    }
    [UIView commitAnimations];
}

#pragma mark 键盘消失操作

- (void)keyboardwillhidden:(NSNotification *)notification
{
    self.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}

- (void)createKeyboardNotification
{
    //键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardwillhidden:)
                                                 name:UIKeyboardWillHideNotification object:nil];
}

posted on 2015-09-23 16:59  MichaelMao  阅读(1246)  评论(0编辑  收藏  举报