【问题标题】:ios UITextView when keyBoard Hidden,text also retain my viewios UITextView 当键盘隐藏时,文本也保留我的视图
【发布时间】:2013-06-25 19:46:05
【问题描述】:

我将UITextView 添加到UIToolBar。 当我完成我的UITextView 时,键盘被隐藏了,但文本也保留了我的视图。

当我开始我的UITextView时,照片链接:

当我完成我的UITextView,照片链接:

【问题讨论】:

    标签: iphone ios objective-c keyboard uitextview


    【解决方案1】:

    当键盘可见时,您必须为视图设置动画。喜欢:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    CGRect rect=self.view.frame;
    rect.origin.y=rect.origin.y-100;
    self.view.frame=rect;
    [UIView commitAnimations];
    

    您可以根据需要调整 100 的值。然后在钥匙消失时做相反的过程。

    【讨论】:

    • 是的,我是这样做的,但我 setAnimationDuration 是 0.3
    • 你用什么方法放这个?请添加一些断点
    • 我 setAnimationDuration 是 0.5,而且看起来好多了
    • 但如果你将它设置为 0.3 那么它实际上也应该无关紧要。在这种情况下您无法体验动画。但是如果这对您有帮助,您可以接受答案
    • 帮帮我!谢谢!我发现也许添加一个进度是最好的,谢谢!!
    【解决方案2】:
    - (void)keyboardWasShown:(NSNotification*)aNotification
    {
        NSDictionary* info = [aNotification userInfo];
        CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    
        [UIView animateWithDuration:0.2f animations:^{
    
            CGRect frame = textInputView.frame;
            frame.origin.y -= kbSize.height;
            textInputView.frame = frame;
    
            frame = bubbleTable.frame;
            frame.size.height -= kbSize.height;
            bubbleTable.frame = frame;
        }];
    }
    
    - (void)keyboardWillBeHidden:(NSNotification*)aNotification
    {
        NSDictionary* info = [aNotification userInfo];
        CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    
        [UIView animateWithDuration:0.2f animations:^{
    
            CGRect frame = textInputView.frame;
            frame.origin.y += kbSize.height;
            textInputView.frame = frame;
    
            frame = bubbleTable.frame;
            frame.size.height += kbSize.height;
            bubbleTable.frame = frame;
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-30
      • 1970-01-01
      • 2022-01-10
      • 2011-08-23
      • 2015-02-22
      • 2012-07-16
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      相关资源
      最近更新 更多