2011-09-16 12 views
0

私はそのテキストフィールドを押すと、スクロールビューを使用して私はそのテキストフィールドを表示するスクロールダウン誰もplsなぜ私はその起こっている?日付ピッカーコントローラは、選択した値を設定する必要がありますiphone

このコードは、スクロール

- (void)keyboardWasShown:(NSNotification*)aNotification { 
    if (keyboardShown) 
     return; 
    //static const float deviceHeight = 480; 
    static const float keyboardHeight = 216; 
    static const float gap = 5; //gap between the top of keyboard and the control 

    //Find the controls absolute position in the 320*480 window - it could be nested in other views 
    CGPoint absolute = [activeField.superview convertPoint:activeField.frame.origin toView:nil]; 
    //NSLog(@"Keyborad Shown %f : %f",absolute.y,(keyboardHeight + gap); 
    if (absolute.y > (keyboardHeight + gap)) { 

     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.3f]; //this is speed of keyboard 
     NSDictionary* info = [aNotification userInfo]; 
     CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
     CGRect bkgndRect = activeField.superview.frame; 
     bkgndRect.size.height += kbSize.height; 
     [activeField.superview setFrame:bkgndRect]; 
     [scrollview setContentOffset:CGPointMake(0.0, activeField.frame.origin.y-92) animated:YES]; 

     [UIView commitAnimations]; 
    } 

    keyboardShown = YES; 
} 

// Called when the UIKeyboardDidHideNotification is sent 
- (void)keyboardWasHidden:(NSNotification*)aNotification { 

    //[UIView beginAnimations:nil context:nil]; 
    //[UIView setAnimationDuration:0.003f]; //this is speed of keyboard 


    NSDictionary* info = [aNotification userInfo]; 

    // Get the size of the keyboard. 
    NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; 
    CGSize keyboardSize = [aValue CGRectValue].size; 

    // Reset the height of the scroll view to its original value 
    CGRect viewFrame = [scrollview frame]; 
    viewFrame.size.height += keyboardSize.height; 
    scrollview.frame = viewFrame; 

    //[UIView commitAnimations]; 

    keyboardShown = NO; 
} 

- (void)textFieldDidBeginEditing:(UITextField *)textField {  
    activeField = textField; 
} 

答えて

0

のために使用していますあなたがscrollviewのアップをスクロールするためにこのコードを参考に私の

....これを試してみてください。

  • (BOOL)textViewShouldBeginEditing:(UITextView *)のTextView {

    [scrView setContentOffset:CGPointMake(0、textView.frame.origin.y - 20)]。 return YES; }

関連する問題