まず、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];
}
キーボードが消えると、ピッカービューが表示されます。
これをもう少し取りたい場合は、UIPickerViewの「スライドイン」をキーボードのようにアニメートできます。
- (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
ちょうどメモとして、これはこれを行う古い方法です。より最新のバージョンでは、textFieldのinputViewプロパティを使用します。 –