iOSアプリ開発初心者です。サンプルのログイン ページでは、ビュー内に多くのビュー オブジェクトがあります。画面の下部にあるテキスト フィールドを編集しようとすると、キーボードが表示され、編集する必要があるビュー オブジェクトの上に表示されます。そのため、ビュー オブジェクトキーボード自体で覆われています。キーボードが表示されている場合でも、画面の下部にあるすべてのビュー オブジェクトを適切に表示するにはどうすればよいですか? 前もって感謝します。
1 に答える
0
スクロール ビューを追加し、コントロールを表示し、キーボード通知を追加し、スクロール コンテンツを調整します。
適切なドキュメントはこちらから入手できます
- (void)viewDidLoad
{
@try
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
@catch (NSException *exception)
{
NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
}
}
- (void)keyboardWasShown:(NSNotification *)notification
{
@try
{
// Step 1: Get the size of the keyboard.
CGSize keyboardSizePotriat = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGSize keyboardSize = {keyboardSizePotriat.height,keyboardSizePotriat.width};
// Step 2: Adjust the bottom content inset of your scroll view by the keyboard height.
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
self.theScrollView.contentInset = contentInsets;
self.theScrollView.scrollIndicatorInsets = contentInsets;
CGPoint scrollPoint = CGPointMake(0.0, self.txtMRN.frame.origin.y - (keyboardSize.height - 45));
[self.theScrollView setContentOffset:scrollPoint animated:YES];
}
@catch (NSException *exception)
{
NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
}
}
- (void) keyboardWillHide:(NSNotification *)notification
{
@try
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.theScrollView.contentInset = contentInsets;
self.theScrollView.scrollIndicatorInsets = contentInsets;
}
@catch (NSException *exception)
{
NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
}
}
于 2013-03-17T02:21:52.170 に答える