gpt4 book ai didi

iphone - 用 UIPickerView 优雅地替换 iPhone 键盘

转载 作者:行者123 更新时间:2023-12-03 18:23:42 24 4
gpt4 key购买 nike

我有一个 TableView ,其中嵌入了用于输入一些数据的 UITextFields。它还具有另外两个字段,用于弹出 UIPickerView 和 UIDatePicker - 如 Apple 的 DateCell 示例所示。

大多数情况下它可以工作,但我不知道如何干净地从文本字段键盘过渡到其他选择器 - 一个滑出,一个滑入 - 它看起来很奇怪,并且表格 View 上的滚动位置有时会搞砸- 所有内容都从顶部滚动。

我想做的是替换文本字段键盘,而不使其动画消失,也不将表格 View 恢复到完整大小。

有什么线索吗?

最佳答案

首先,这是一个 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];
}

当键盘消失时,选择器 View 就会可见。

如果您想更进一步,您可以像键盘一样为 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;
}

关于iphone - 用 UIPickerView 优雅地替换 iPhone 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1275633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com