0

iPhoneの基本的な質問をしたいと思います。iPhone ビューに多くの TextField があります。タップして TextField に入力すると、キーボードが表示され、他の TextField が非表示になります。親ビューをスクロール可能にしたいと思います。サンプルコードを見せていただけますか?

どうもありがとうございました

4

3 に答える 3

2

キーボードの上下の通知を聞くことができます。ビューをキーボードの高さのすぐ上に移動します。

ViewWillAppearメソッドでは:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];

ViewWillDisAppearメソッドでは:

  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 

次に、バーの位置を調整するために上記のメソッドを使用します。

-(void) keyboardWillShow:(NSNotification *) note
{
    CGRect r  = bar.frame, t;
    [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
    r.origin.y -=  t.size.height;
    bar.frame = r;
}




 -(void) keyboardWillHide:(NSNotification *) note
    {
        CGRect r  = bar.frame, t;
        [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
        r.origin.y +=  t.size.height;
        bar.frame = r;
    }
于 2011-03-16T09:38:54.633 に答える
1

親ビューがUIScrollViewの場合は、テキストフィールドデリゲートのようなものを試してください

- (BOOL) textFieldShouldReturn:(UITextField *)theTextField
{   

    if (theTextField == textFieldName) {
        [scroll scrollRectToVisible:CGRectMake(0, 160, 280, 440) animation:YES];// それに応じて四角形を選択します。
    }
    はいを返します。

}
于 2011-03-16T09:51:41.917 に答える