Scroll to a specific text field by scrolling scroll or scroll down when the keyboard is on screen

I'm stuck here

I have my own scrollview in the scroll view, which has an add field button that allows the user to add a new text field to the scrollview. When the user clicks on a specific text field keyboard and hides the text field to overcome this, I followed the UICatalog example, but it moves the whole scroll up

to prevent this, I executed the UICatalog example and did it

-(void)textFieldDidBeginEditing:(UITextField *)sender
{

if (sender.frame.origin.y>109) {
    moveScrollViewUpBy=(sender.frame.origin.y-109+10);

    [self viewMovedUp:YES];
}
}


-(void)viewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

CGRect rect = formScrollView.frame;
if (movedUp)
{
    if(rect.origin.y == 0.0f){
        rect.origin.y -= kOFFSET_FOR_KEYBOARD;
        rect.size.height += kOFFSET_FOR_KEYBOARD;
    }
}
else
{
    if(rect.origin.y != 0.0f){
        rect.origin.y += kOFFSET_FOR_KEYBOARD;
        rect.size.height -= kOFFSET_FOR_KEYBOARD;
    }
}
self.formScrollView = rect;


[UIView commitAnimations];
}

here

#define kOFFSET_FOR_KEYBOARD    160.0

but it shifts the scroll view up,

I want that when I click the text box below in the scroll, scroll through the scroll scrolls and the text box appears ....

Can this be done ... otherwise suggest a different solution

srollview , .

+3
2

, scrollView contentOffset, .

+2

UITextViewDelegate :

- (void)textViewDidBeginEditing:(UITextView *)textView {

    keyboardShowing = YES; //helper ivar
    [self sizeToOrientation];
    [self.scrollView scrollRectToVisible:textView.frame animated:YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    keyboardShowing = NO;
    [self sizeToOrientation];
}

:

//fit to the appropriate view sizes
- (void)sizeToOrientation {
    CGSize size;
    if( keyboardShowing )
        size = CGSizeMake(320, 190); //make room for keyboard
    else
        size = CGSizeMake(320, 420); //full height with tabbar on bottom

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

.

+1

Source: https://habr.com/ru/post/1727018/


All Articles