今天看啥
热点:

IOS开发—获取ios软键盘高度



- (void)viewDidLoad { [super viewDidLoad]; //增加监听,当键盘出现或改变时收出消息 

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardDidShow:)

                                                 name:UIKeyboardWillShowNotification

                                               object:nil];

//增加监听,当键退出时收出消息

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardDidHide:)

                                                 name:UIKeyboardWillHideNotification

                                               object:nil];

}
//当键盘出现或改变时调用

- (void)keyboardDidShow:(NSNotification *)notification{

    NSDictionary *userInfo = [notification userInfo];

    CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    _keyBoardHeight = keyboardSize.height;

    [self changeViewYByShow];

}

 


//当键盘隐藏时调用


- (void)keyboardDidHide:(NSNotification *)notification{

    _keyBoardHeight = 0;

    [self changeViewYByHide];

}




#pragma mark - private methods

- (void)changeViewYByShow{

    [UIView animateWithDuration:0.2 animations:^{

        CGRect rect = self.view.frame;

        rect.origin.y -= self.keyBoardHeight;

        self.view.frame = rect;

    }];

}


- (void)changeViewYByHide{

    CGRect rect = self.view.frame;

    rect.origin.y = 64;

    self.view.frame = rect;

}


						

www.bkjia.comtruehttp://www.bkjia.com/IOSjc/997070.htmlTechArticleIOS开发—获取ios软键盘高度 - (void)viewDidLoad { [super viewDidLoad]; //增加监听,当键盘出现或改变时收出消息 [[ NSNotificationCenter defaultCenter ] add...

相关文章

相关搜索: 高度 键盘

帮客评论

视觉看点