2012-04-21 9 views
2

私はgpsnoteでプロジェクトをやっています。誰もがこのアプリケーションABT任意の情報を持っている場合、plzは私はテキストフィールドが私のキーボードと一緒に来る必要がありiphone sdkのキーパッドと一緒にテキストフィールドを取得する方法

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
} 

おかげ

+0

をresetingしているときに、テキストフィールドのデリゲートを使用する必要があり、このために、以下のデリゲートがトリガされますテキストフィールド。 – rishi

答えて

0

まず上にコンテンツを設定したいBT私はこのコードを知っている...

私を導きますスクロールビューとのviewDidLoadでスクロールビュー設定:通知以下の追加viewWillAppearで、その後

[scrollView setContentSize : CGSizeMake (320, 1040)]; 

を:

私たちがやっていることkeyboardWasShown機能で

- (void)keyboardWasShown:(NSNotification*)aNotification { 

NSDictionary* info = [aNotification userInfo]; 
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 

double keyboardHeight = kbSize.height; 
double screenHeight = [UIScreen mainScreen].bounds.size.height - 20; 

if(textOrigin > screenHeight - keyboardHeight) 
{ 
    double sofset = textOrigin - (screenHeight - keyboardHeight); 
    CGPoint offset = scrollBackGround.contentOffset; 
    offset.y += sofset; 
    [scrollBackGround setContentOffset:offset animated:YES]; 
} 

} 


- (void)keyboardWillBeHidden:(NSNotification*)aNotification 
{ 
    [scrollBackGround setContentOffset:CGPointMake(0, 0) animated:YES]; 
} 

通知によって呼び出される2つの関数がちょうどあり、次のとおり

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(keyboardWillBeHidden:) 
              name:UIKeyboardWillHideNotification object:nil]; 

を隠すキーボードの場合

キーボードについて

​​

を示しますキーボードの高さを取得し、textFieldのy軸(関数内のtextOrigin)が大きいかどうかを確認しますテキストのフィールドを含むスクロールビューの内容を上にスライドさせるよりも、キーボードのY軸を大きくする必要があります。

NOwテキストフィールドY軸を取得する方法。あなたのテキストフィールドが

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    textOrigin = scrollBackGround.frame.origin.y + textField.frame.origin.y + 20(it is status bar height) + yourNavigationBarheight; 

// Make sure to make textOrigin an ivar in your .h file 
} 

をファーストレスポンダになり、最終的にはkeyboardWillBeHiddenに我々はyoouが一緒にキーボード用becomeFirstResponderを使用することができますscrollviewのcontentview

+0

あなたの貴重なヒントをありがとう.................... – user1347963

+0

おかげで仲がいい:) – superGokuN

関連する問題