I have made an app with a Registration form. When the Textfield in this form is selected it gets hidden by the soft keyboard. If i leave it as it is user can't see what he is entering while typing.
            Asked
            
        
        
            Active
            
        
            Viewed 88 times
        
    0
            
            
        - 
                    I think you wants to move your textfield to up when editing.. I am right or wrong ... – Jogendra.Com Jun 12 '14 at 09:38
- 
                    @Rajeev u want to move up & down the textfield when click or touch the textfields – Anbu.Karthik Jun 12 '14 at 09:41
- 
                    that is only a generic problem of a badly designed view-layer. – holex Jun 12 '14 at 09:55
- 
                    You should give us some more info in order to better help you. First, do you have all those textfields on a ScrollView? If yes, do you have the delegate set for textfields? And yes, show us the code you've tried so faR? – GenieWanted Jun 12 '14 at 10:32
2 Answers
1
            
            
        Try this may be helpfull..
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    [self animateTextField:textField up:NO];}
-(void)animateTextField:(UITextField*)textField up:(BOOL)up
{
    int movementDistance = -100; // tweak as needed
    float movementDuration = 0.3f; // tweak as needed
    int movement = (up ? movementDistance : -movementDistance);
    [UIView beginAnimations: @"animateTextField" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}
 
    
    
        Jogendra.Com
        
- 6,394
- 2
- 28
- 35
- 
                    if I use the 20 textfield, it working fine for each textfield, why I ask this ? I tried ur answer it scroll up for each textfield when textfield are shown in the normal time also – Anbu.Karthik Jun 12 '14 at 09:56
- 
                    
- 
                    1
- 
                    @Rajeevleader.. have set textfield delegate or not ... Please implement this if not yet implemented delegate .. "yourTxtField.delegate = self;" – Jogendra.Com Jun 12 '14 at 10:14
0
            this is the old method ,but working fine for each time
in your .h file
@interface signupViewController : UIViewController
{
CGFloat animatedDistance;
 }
.m file
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect =
[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =
[self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator =
midline - viewRect.origin.y
- MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =
(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
    heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
    heightFraction = 1.0;
}
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
 
    
    
        Anbu.Karthik
        
- 82,064
- 23
- 174
- 143
- 
                    
- 
                    
- 
                    
- 
                    it working fine, I used more than 8 projects, k here what the problem u meet – Anbu.Karthik Jun 12 '14 at 11:15
