सबसे पहले, यहां एक screencapture showing how this looks है।
UITextFieldDelegate को कार्यान्वित करें और एक "पॉपअप" प्रदर्शित करें जिसमें UIPickerView शामिल है।
- (void)textFieldDidEndEditing:(UITextField *)textField {
UIPickerView *picker = [[UIPickerView alloc]
initWithFrame:CGRectMake(0, 244, 320, 270)];
picker.delegate = self;
picker.dataSource = self;
[self.view addSubview:picker];
[picker release];
}
जब कीबोर्ड गायब हो जाता है, तो एक पिकर दृश्य तब दिखाई देता है।
यदि आप इसे थोड़ा और लेना चाहते हैं, तो आप कीबोर्ड की तरह यूआईपीकर व्यू "स्लाइड इन" को एनिमेट कर सकते हैं।
- (void)viewDidLoad {
//picker exists in the view, but is outside visible range
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 480, 320, 270)];
picker.delegate = self;
picker.dataSource = self;
[self.view addSubview:picker];
[picker release];
}
//animate the picker into view
- (void)textFieldDidEndEditing:(UITextField *)textField {
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.5];
picker.transform = CGAffineTransformMakeTranslation(0,-236);
[UIView commitAnimations];
}
//animate the picker out of view
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.5];
picker.transform = CGAffineTransformMakeTranslation(0,236);
[UIView commitAnimations];
}
//just hide the keyboard in this example
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
इस उत्तर के लिए धन्यवाद। – camilo
बस एक नोट के रूप में, यह करने का यह पुराना तरीका है। एक और 'आधुनिक' संस्करण टेक्स्ट फ़ील्ड की इनपुट व्यू प्रॉपर्टी का उपयोग करेगा। –