iOS键盘弹起,上移视图,和其它的方法大同小异,只不过我在viewDidLayoutSubviews 中写的改变frame方法,这样就不用监听键盘什么的了

在各个代理方法中,执行相应的代码。如下


- (void)textViewDidBeginEditing:(UITextView *)textView

{

    _isEditing = YES; // 定义的是否处于编辑状态

}


- (void)textViewDidEndEditing:(UITextView *)textView

{

    _isEditing = NO;

    self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

    

}

- (void)viewDidLayoutSubviews

{

    DLog(@"我执行了");

    if (_isEditing) {

        CGRect frame = self.commentContent.frame;

        int offset = frame.origin.y + 125 - (self.view.frame.size.height - 216.0);//键盘高度216

        NSTimeInterval animationDuration = 0.3; // ResizeForKeyBoard

        

        [UIView beginAnimations:@"keyboard" context:nil];

        

      

        [UIView setAnimationDuration:animationDuration];

        

        [UIView animateWithDuration:animationDuration animations:^{

            

        }];

        //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示

        if (offset >0) {

            self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);

            [UIView commitAnimations];

        }

    }

    [super viewDidLayoutSubviews];

    [self.view layoutSubviews];

    


}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    [self.commentContent resignFirstResponder];

}



- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

    if ([text isEqualToString:@"\n"]) {

        [textView resignFirstResponder];

        

    }

    return YES;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值