日期选择器控制器需要设置所选的iphone值

时间:2011-09-16 04:47:06

标签: iphone ios uidatepicker

我正在使用scrollview作为文本字段当我按下该文本字段时,视图向下滚动任何人都可以帮助我为什么会发生这种情况?

此代码用于滚动

- (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;
}

1 个答案:

答案 0 :(得分:0)

试试这个......

此代码可帮助您滚动滚动浏览。

  • (BOOL)textViewShouldBeginEditing:(UITextView *)textView {

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