Date Picker控制器需要设置iphone选择的值

发布于 2024-12-05 04:12:30 字数 2100 浏览 0 评论 0原文

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

这段代码用于滚动

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

am using scrollview for text field when i press that text field the view scrolling down can anyone pls help me why its happening ?

This code am using for scroll

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷月断魂刀 2024-12-12 04:12:30

试试这个......

这段代码可以帮助您向上滚动滚动视图。

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

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

Try This....

This code my be helpful for you to scroll your scrollview up.

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文