views:

761

answers:

2

hello,

I got stuck in here,

I have a custom scrollview in a view this scroll view has an add field button which lets user to add new text field to the scrollview. When user taps on a particular textfield keyboard appears and hide the textfield, to overcome this I followed UICatalog example, but it moves the whole scrollview up

to prevent this I followed UICatalog example and did this

-(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 this shifts the scroll view up,

I want that when i tap on a textfield down below in scroll view... scroll view scrolls and that textfield appears....

is it possible to do so....otherwise suggest me some other solution

I have one more query srollview just stop scrolling while the keyboard stays on screen. Is there any way to overcome this

+1  A: 

You probably just want to set the scrollView's contentOffset property, rather than adjust its bounds.

Ben Gottlieb
thnx for support let me try and check
Ankit Sachan
A: 

Implement the UITextViewDelegate and do the following:

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

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

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

Helper method:

//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);
}

This works well for me.

bentford
you rock dude........thnx alot
Ankit Sachan