I have add a view with button in UITableView Header . I have set the height properly, and the button is actually functional when keyboard is not shown. When some textfield was pressed (UIT开发者_运维百科extField in Cell) keyboard will shown, and I have set the table view frame to smaller, so the cell can be clicked, but the problem is the button — when the button is intersect some of it in tableview (when button is not fully shown), the button is not functional and it is functional when the button is fully shown.
I have tried it by placing the button in scroll view instead of placing in the footer or tableview header, it works perfectly. Is this some kind of UITableView header bug? Can it be fixed?
Add following in your code :
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
if(textField.tag != [[[yourTable indexPathsForVisibleRows] objectAtIndex:0]row])
[self animateTextField: textField up: NO];
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if(textField.tag != [[[yourTable indexPathsForVisibleRows] objectAtIndex:0]row])
[self animateTextField: textField up: YES];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 300; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
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];
}
精彩评论