简体   繁体   English

iPhone上的键盘覆盖textview

[英]Keyboard covering textview on iPhone

I am newbie for iPhone application. 我是iPhone应用程序的新手。 Below is what I have... 以下是我所拥有的...

在此处输入图片说明

When I enter Item name, I get proper screen with Done option. 输入项目名称时,可以看到带有完成选项的正确屏幕。 When I click Done, keyboard get hided. 当我单击“完成”时,键盘被隐藏。

在此处输入图片说明

Same happen for Time also. 时间也一样。

Now when I click on description and type something, I get screen as below. 现在,当我单击描述并输入内容时,将显示如下屏幕。

在此处输入图片说明

Now my problem is, I can't see UITextView and because of that I can't see what I am typing. 现在我的问题是,我看不到UITextView ,因此看不到我在键入什么。

How can I show the UITextView so that I can see what I am typing. 如何显示UITextView以便可以看到输入的内容。


Update 1 更新1

在此处输入图片说明

First take these whole controls in UIScrollView and set as it is, 首先将整个控件放在UIScrollView并按原样进行设置,

after just in UITextView delegate method textViewDidBeginEditing set the frame of view like bellow... 只需在UITextView委托方法textViewDidBeginEditing设置像下面这样的视图框架...

-(void)textViewDidBeginEditing:(UITextView *)textView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    yourScrollView.frame = CGRectMake(yourScrollView.frame.origin.x, -160, yourScrollView.frame.size.width, yourScrollView.frame.size.height);
    [UIView commitAnimations];

}

and also set same like before after return like bellow... 并且还像波纹管一样在返回之前设置为...

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) 
    {
        [textView resignFirstResponder];
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];

        yourScrollView.frame = CGRectMake(yourScrollView.frame.origin.x, 0, yourScrollView.frame.size.width, yourScrollView.frame.size.height);
        [UIView commitAnimations];
        return NO;
    }
    return YES;
}

you can also set the frame of UIView instead of UIScrollView .. 您还可以设置UIView的框架,而不是UIScrollView

Also first give the Delegate to UITextView and add this delegate in .h file 还要首先将Delegate赋予UITextView并将此委托添加到.h文件中

i hope this helpful to you... 我希望这对您有帮助...

set following code in viewDidLoad for key board hide/show notification 在viewDidLoad中为键盘隐藏/显示通知设置以下代码

  [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardDidShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillBeHidden:)
                                                 name:UIKeyboardWillHideNotification object:nil];

and set this method and change the frame of view in this code 并设置此方法并更改此代码中的视域

- (void)keyboardWasShown:(NSNotification *)aNotification
{

}

- (void)keyboardWillBeHidden:(NSNotification *)aNotification
{

}

Put all the content in a UIScrollView and use the scrollRectToVisible:animated: to scroll to the correct TextField when it is active. 将所有内容放在UIScrollView并在活动时使用scrollRectToVisible:animated:滚动到正确的TextField

Also you have to resize the scrollview according to if the keyboard is shown or not, so you need to set up TextField delegates 另外,还必须根据是否显示键盘来调整滚动视图的大小,因此需要设置TextField delegates

使用UIScrollView在设计所有控件的背后和设置contentsize的它beginEditingTextViewTextFieldShouldReturn秒(时间)文本框的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM