2011-09-16 86 views
0

上午使用scrollview的文本字段時,當我按下該文本字段視圖向下滾動任何人都可以幫助我爲什麼會發生?日期選擇器控制器需要設置選擇的值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

試試這個....

此代碼我有所幫助,爲您滾動鼠標滾動型的。

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

    [scrView setContentOffset:CGPointMake(0,textView.frame.origin.y - 20)]; 返回YES; }