0

iOS 6 を使用UIViewControllerしていUIScrollViewます。これScrollViewはログイン画面です。つまり、ログインするためのラベル、テキスト フィールド、およびボタンです。

キーボードが飛び出したときに適切なフィールドにスクロールするために、Apple 開発者ドキュメントの次のコードを使用します。

// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    CGRect bkgndRect = self.activeField.superview.frame;
    bkgndRect.size.height += kbSize.height;
    [self.activeField.superview setFrame:bkgndRect];
    [self.scrollView setContentOffset:CGPointMake(0.0, self.activeField.frame.origin.y-kbSize.height) animated:YES];
}

- (void)resetUIEdgeInsets
{
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    self.scrollView.contentInset = contentInsets;
    self.scrollView.scrollIndicatorInsets = contentInsets;
}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    [self resetUIEdgeInsets];
}

- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self resetUIEdgeInsets];
    [self registerForKeyboardNotifications];
}

それは正常に動作します。この問題は、モーダルで別のビュー コントローラーにセグエして、ここに戻ると発生します。スクロール位置が(断続的に)完全にスペースから外れていることがあります。

私はここで何か間違ったことをしていますか?ありがとう

4

1 に答える 1

0

scrollView の名前を別の名前に変更してみてください。以前も同じ問題がありました。同じ vc に 2 つの UIScrollView があり、モーダル ビューが表示された後、それらの 1 つが常に見当違いでした。

于 2012-12-10T07:37:19.373 に答える