I shift a modal view up when the keyboard is displayed to prevent some parts of the interface being hidden by the keyboard.
When the view has been shifted, the toolbar cancel / save buttons don’t respond to taps. Taps inside the modal are detected and respond fine.

I’ve set it up so that the keyboard should dismiss when tapping outside the textfield, but this doesn’t work when tapping on the navigation bar either.
How can I respond appropriately to taps on barbuttonitems when the view has been offset?
Here’s how I am shifting the modal up when the keyboard is displayed:
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
int movementDistance;
float movementDuration;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if(
UIInterfaceOrientationIsLandscape(self.interfaceOrientation)
)
{
//code for landscape shift - not relevant because you can't see the toolbar
else{
NSLog(@"Portrait for animation");
movementDistance = IPAD_PORTRAIT_KEYBOARD_HEIGHT;
movementDuration = KEYBOARD_ANIMATION_DURATION;
if(up){
keyboardAppearedInLandscape = false;
}else{
//the keyboard is going down
NSLog(@"Keyboard going down");
//is the iPad in the same orientation now that it was when it came up?
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown)
{
if (!keyboardAppearedInLandscape) {
//don't do anything - the keyboard is being dismissed in the same way it was called. It's much the same in any case.
}else{
movementDistance = IPAD_LANDSCAPE_KEYBOARD_HEIGHT;
}
}
}
}
}
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];
}
//end text field movy-ness
And here is how I am detecting taps outside the textfield to dismiss the keyboard:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//keyboard goes away if you tap somewhere else on screen
NSLog(@"resignFirstResponder");
[self.view endEditing:YES];
}
[super touchesBegan:touches withEvent:event];
}
You won’t receive touch events outside the original rectangle bounds, because…
SuperViewthinks that the view hasn’t changed locationInstead, to move the subview properly:
SuperViewshould be responding to theUIKeyboardUIKeyboardWillHideNotification&&UIKeyboardWillShowNotificationClipsToBounds to YESCheck out: