1

atmの下のコードを使用します。キーボードが起動している間にアプリを終了しない限り(ホームを押す)、正常に動作しています。だから私は単純に、viewWillDissappear:(BOOL)animatedでresignFirstResponderだけだと思ったが、どうやらホームを押すとは呼ばれない...

問題のシナリオの簡単な要約: textView をタップ -> キーボードが表示され、ビューがシフト ホームを押す アプリをもう一度開く -> キーボードがまだ表示されている、ビューが元の場所に戻ったため、コンテンツが表示されない

 - (void)viewDidLoad
    {
        [super viewDidLoad];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }

- (void) keyboardWillShow: (NSNotification*) aNotification;
    {       
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        CGRect rect = [[self view] frame];
        rect.origin.y -= 60; 
        [[self view] setFrame: rect];
        [UIView commitAnimations];
    }

    - (void) keyboardWillHide: (NSNotification*) aNotification;
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        CGRect rect = [[self view] frame];
        rect.origin.y += 60;
        [[self view] setFrame: rect];
        [UIView commitAnimations];
    }
4

1 に答える 1

0

次のコードのように、enter background イベントの通知を追加できます。

 - (void)viewDidLoad
{
    //Add this 
    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(handleEnteredBackground:) 
                                                 name: UIApplicationDidEnterBackgroundNotification
                                               object: nil];
}

そして関数では

- (void) handleEnteredBackground:(NSObject*)obj
{
    //Adjust your views   
}
于 2012-06-22T10:18:54.080 に答える