2011-07-29 5 views
0

私は簡単なノートブロックアプリケーションを作成しようとしています。私はAQGridViewを使ってグリッドにノートブロックを表示しています。すべてのノートブロックには、AQGridViewCellのカスタムサブクラス(TableViewCellに似ています)の編集可能なUITextFieldプロパティがあります。キーボードの操作にはいくつか問題があります。私はこのガイド、http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.htmlに従おうとしました。私は(cellForRowAtIndexPathに類似)cellForItemAtIndexにおけるテキストフィールドのデリゲートを設定AQGridViewで選択したtextFieldにスクロールします(tableViewと同様)

- (void)keyboardWillShow:(NSNotification *)notification 
{ 

    // Animates the done button. 
    [UIView beginAnimations:nil context:NULL]; 

    // Display a done button 
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(hideKeyboard)]; 
    [[self navigationItem] setRightBarButtonItem:doneButton]; 

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

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0); 
    self.gridView.contentInset = contentInsets; 
    self.gridView.scrollIndicatorInsets = contentInsets; 

    // If active text field is hidden by keyboard, scroll it so it's visible 
    // Your application might not need or want this behavior. 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= kbSize.height; 
    NSLog(@"%f", activeField.frame.origin.y); 
    if (!CGRectContainsPoint(aRect, activeField.frame.origin)) { 
     CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y+kbSize.height); 
     [self.gridView setContentOffset:scrollPoint animated:YES]; 
    } 

} 

// Called when the UIKeyboardWillHideNotification is sent 
- (void)keyboardWillBeHidden:(NSNotification *)notification 
{ 
    // Remove the "done" button 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 

    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    self.gridView.contentInset = contentInsets; 
    self.gridView.scrollIndicatorInsets = contentInsets; 

} 

:私はこのようなkeyboardWillShowとkeyboardWillBeHiddenメソッドを実装しました。

現在のところ、正しい位置へのスクロールは正しく機能しません。私は、私がテストしたときので、問題は、テキストフィールドとしなければならないと思う:

// activeField is a UITextField property that I set in textFieldDidBeginEditing, 
// and later set to nil in textFieldDidEndEditing. 
NSLog(@"%f", activeField.frame.origin.y); 

それは常に選択テキストフィールドが同じ行にない場合でも、私の場合95には、同じ値を返します。

これを解決する方法や他の解決策についてのヒントは素晴らしいと思います!

答えて

0

私は、タグをセルのtextFieldに設定して、そのタグ/インデックスからセルを取得することで解決したと思います。次に、セル内のtextFieldではなく、セルの位置に基づいてキーボードが表示されたときの位置を計算します。