键盘

来源:互联网 发布:别人复制你的淘宝宝贝 编辑:程序博客网 时间:2024/04/30 08:09
键盘操作:    //监听键盘的通知    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];/** *  当前键盘改变了frame(键盘的位置和尺寸的时候调用) */- (void)keyboardWillChangeFrame:(NSNotification *)note{    //设置窗口的颜色    self.view.window.backgroundColor = self.tableView.backgroundColor;        //0、取得动画的时间    CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];        //1、取得键盘最后的frame    CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];        //2、计算控制器View需要平移的距离    CGFloat transformY = keyboardFrame.origin.y - self.view.frame.size.height;        //3、设置一个动画    [UIView animateWithDuration: duration animations:^{        //4、键盘弹出与影藏        self.view.transform = CGAffineTransformMakeTranslation(0, transformY);     }];}/** *  有addobserver就必须有removeobserver */- (void)dealloc{    [[NSNotificationCenter defaultCenter] removeObserver:self];}

0 0
原创粉丝点击