开发者

Bring to front DatePicker on an UITextField

When an UITextField is firstResponder, I would like to bring to front an UIDatePicker (bottom part of the screen) without the "going down keyboard" (no call to UITextField resignFirstResponder).

The aim is to process like UIKeyboard of UITextField which pop-up on nearly everything when it becomeFirstResponder. modalViewController seems to be fullscreen only.


- showDatePicker:(id)sender {
    if([taskName isFirstResponder]) [taskName resignFirstResponder];
    [self.view.window addSubview: self.pickerView];

    // size up the picker view and compute the start/end frame origin
    (...)
    [UIView commi开发者_JAVA百科tAnimations];

}

This example is an animation of keyboard going down, and DatePicker going up, behind and not in front.

Do you know a solution ? A piece of code would be welcome. Thanks in advance.


This is simply done by setting the input view of the text field to the Picker View. Then, on Editing did begin tell the picker view to becomeFirst responder. Like this

textField.inputView = pickerView

then using an IBAction called when the Editing Did Begin

-(IBAction) setPickerViewAsFirstResponder:(id)sender
{
    [pickerView becomeFirstResponder];
}

This works perfectly. You'll need to implement code to actually set what the picker view is currently showing to be a string in the text field still.


This definitely can be done... simply implement the method below after setting UIViewController <UITextFieldDelegate> in your .h

Long story short, this overrides the keyboard loading before text editing begins.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    // Make a new view, or do what you want here
    UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,245,0,0)];
    [self.view addSubview:pv];
    return NO;  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜