iPhoneの基本的な質問をしたいと思います。iPhone ビューに多くの TextField があります。タップして TextField に入力すると、キーボードが表示され、他の TextField が非表示になります。親ビューをスクロール可能にしたいと思います。サンプルコードを見せていただけますか?
どうもありがとうございました
iPhoneの基本的な質問をしたいと思います。iPhone ビューに多くの TextField があります。タップして TextField に入力すると、キーボードが表示され、他の TextField が非表示になります。親ビューをスクロール可能にしたいと思います。サンプルコードを見せていただけますか?
どうもありがとうございました
キーボードの上下の通知を聞くことができます。ビューをキーボードの高さのすぐ上に移動します。
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;
}
親ビューがUIScrollViewの場合は、テキストフィールドデリゲートのようなものを試してください
- (BOOL) textFieldShouldReturn:(UITextField *)theTextField { if (theTextField == textFieldName) { [scroll scrollRectToVisible:CGRectMake(0, 160, 280, 440) animation:YES];// それに応じて四角形を選択します。 } はいを返します。 }