インターフェイスの一部がキーボードで隠れないように、キーボードが表示されているときにモーダル ビューを上に移動します。
ビューがシフトされている場合、ツールバーのキャンセル/保存ボタンはタップに反応しません。モーダル内のタップが検出され、正常に応答します。
テキストフィールドの外側をタップするとキーボードが消えるように設定しましたが、ナビゲーションバーをタップしても機能しません。
ビューがオフセットされているときに、barbuttonitem のタップに適切に応答するにはどうすればよいですか?
キーボードが表示されているときにモーダルを上にシフトする方法は次のとおりです。
- (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
そして、キーボードを閉じるためにテキストフィールドの外でタップを検出する方法は次のとおりです。
- (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];
}