views:

1110

answers:

1

is there any way to move some textfield in a simple UIView up so that they could not be hide behind the keyboard.? is it possible without using UIScrollView

A: 

It should be possible just be adjust the frame position of the view the UITextField is on. check out this code:

http://iphoneincubator.com/blog/tag/uitextfield

- (void)textFieldDidBeginEditing:(UITextField *)textField {  
    [self scrollViewToCenterOfScreen:textField];  
}  

- (void)scrollViewToCenterOfScreen:(UIView *)theView {  
    CGFloat viewCenterY = theView.center.y;  
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];  

    CGFloat availableHeight = applicationFrame.size.height - keyboardBounds.size.height;            // Remove area covered by keyboard  

    CGFloat y = viewCenterY - availableHeight / 2.0;  
    if (y < 0) {  
        y = 0;  
    }  
    scrollView.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);  
    [scrollView setContentOffset:CGPointMake(0, y) animated:YES];  
}
Dutchie432
i want to do this without scroll view sir.. you have used scroll view
Rahul Vyas
Just substitute the scrollView variable with your current view. I have used this code with scrollviews, views, and tableviews. The code essentially just figures out where your textfield is and calculates the animatedDistance. Use this variable to adjust your view's frame.
Dutchie432