如何在文本归档时弹出datePicker,在编辑完成后消失 [英] how to pop up datePicker when text filed click and disappear when editing done

查看:154
本文介绍了如何在文本归档时弹出datePicker,在编辑完成后消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看类似下面的内容


日期选择器视图总是在那里我怎么能在点击输入日期时弹出它,当我点击背景然后日期选择器应该下降

date picker view is always there how can i make it appear pop up when Enter date is clicked and when i click on back ground then date picker should go down

我刚刚做了日期选择器视图习惯,但我不知道怎么做这个出现并消失的东西

i have just made date picker view customary but i dont know how to do this appear and disappear thing

推荐答案

好。下面是一些动画要求的示例代码。

Ok. Here is some sample code for your requirement with animation.

- (void) showView
{
    [self.view addSubview:yourDatePickerView];
        yourDatePickerView.frame = CGRectMake(0, -250, 320, 50);
        [UIView animateWithDuration:1.0
                         animations:^{
                             yourDatePickerView.frame = CGRectMake(0, 152, 320, 260);
                         }];
}

以下是隐藏DatePickerView的方法

And here is how to hide your DatePickerView

- (void) hideView
{
    [UIView animateWithDuration:0.5
                         animations:^{
                             yourDatePickerView.frame = CGRectMake(0, -250, 320, 50);
                         } completion:^(BOOL finished) {
                             [yourDatePickerView removeFromSuperview];
                         }];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if(textField == yourDateTextField)
    {
         [self showView];
         return NO; // preventing keyboard from showing
    }
    return YES;
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField == yourDateTextField)
    {
         [self hideView];
    }
}

这就是你所需要的。

这篇关于如何在文本归档时弹出datePicker,在编辑完成后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆