我有这个代码在用户开始编辑时为UITextField设置动画(以保持字段在用户查看区域内的焦点)。
#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];
}
此代码效果很好,但是当我开始编辑最后一个文本字段时,会出现如下图所示的黑屏:
如何解决此黑屏并将此颜色更改为我视图的相同颜色(即分组表视图颜色)?