0

I have this code that animate a UITextField when the user begin edit (To keep the focus of the field within the User viewing area).

#pragma mark - Delegate TextField

- (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{

    NSLog(@"Fui chamado");

    int movementDistance = 0; // tweak as needed
    const float movementDuration = 0.3f; // tweak as needed

    movementDistance = textField.tag * 50;

    int movement = (up ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}

This code works well, but when I begin editing the last textfield, appear a black screen like in this image:

enter image description here

How can I solve this black screen and change this color to the same color of my view (that is Grouped Table view color)?

LettersBa
  • 747
  • 1
  • 8
  • 27
  • This might help , http://stackoverflow.com/a/1127025/3733561 – Saif Aug 27 '15 at 14:23
  • @saif How does that help changing the black area to the desired color? – rmaddy Aug 27 '15 at 14:27
  • 2
    Why do you move your view so high? Just keep it above the keyboard. – Annie Aug 27 '15 at 14:29
  • 1
    The black you see is probably the backgroundColor of your UIWindow, which you have set in your appDelegate – Jasper Aug 27 '15 at 15:12
  • Don't move your view that high... :) – Jadekin Aug 27 '15 at 15:50
  • Yes @Jasper, you solve my problem! I just want to go to app delegate and put this code self.window.backgroundColor = [UIColor groupTableViewBackgroundColor];, inside the didFinishLaunchingWithOptions method, thanks :D – LettersBa Aug 27 '15 at 16:53
  • No problem! However, if you put all your UI on a subview (scrollview or uiview), you would not have to play around with the bg color of your window – Jasper Aug 27 '15 at 16:58

0 Answers0