3

インターフェイスの一部がキーボードで隠れないように、キーボードが表示されているときにモーダル ビューを上に移動します。

ビューがシフトされている場合、ツールバーのキャンセル/保存ボタンはタップに反応しません。モーダル内のタップが検出され、正常に応答します。

ここに画像の説明を入力

テキストフィールドの外側をタップするとキーボードが消えるように設定しましたが、ナビゲーションバーをタップしても機能しません。

ビューがオフセットされているときに、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];

}
4

2 に答える 2

3

元の長方形の境界の外にあるタッチ イベントを受け取ることはありません。

  • SuperViewビューの場所が変わっていないと思う
  • ビューは外側からではなく、ビュー自体の中で上に移動しています
  • 画面上の視覚要素が変化しているが、認識されていない

代わりに、サブビューを適切に移動するには:

  1. SuperViewに応答する必要がありますUIKeyboard
    • UIKeyboardWillHideNotification&&を利用するUIKeyboardWillShowNotification
  2. 設定ClipsToBounds to YES
    • これで、ビューの境界の外にあるものは表示されなくなります。
    • デバッグをより効果的にする

チェックアウト:

于 2012-10-01T22:13:12.843 に答える
0

あなたの問題は、ビューを外側からではなく、それ自体の中で上に移動していることだと思います。そのため、画面上の視覚要素は変化していますが、SuperView によると、ビューは同じ場所にあるため、元の四角形 (この四角形は「境界」と呼ばれます) 内でのみタッチ イベントを取得します。

代わりに、SuperView が応答しUIKeyboardWillShowNotificationUIKeyboardWillHideNotificationサブビューを適切な場所に移動する必要があります。

ClipsToBoundsに設定すると、この種のものをより簡単にデバッグできますYES。これにより、ビューの「境界」(タッチ イベントを受け取ることができる領域) の外にあるものを見ることができなくなります。

于 2012-09-30T23:47:41.740 に答える