gpt4 book ai didi

iphone - 单击按钮时隐藏显示 UIPicker

转载 作者:行者123 更新时间:2023-11-29 04:53:25 25 4
gpt4 key购买 nike

我想做一些类似键盘显示/隐藏的事情,所以我想将选择器设置为第一响应者。这可能吗。如果不是,我如何通过单击按钮在 View 中显示/隐藏 UIPicker。在其他主题上,我如何格式化 DatePicker 输出,现在我得到“2011-12-8 23:00 000000”

最佳答案

您可以将 UIPicker 置于屏幕下方(例如,对于 iPhone,y = 480),然后当您点击按钮时将其移动到 480 - picker.frame.size.height,以便它显示在屏幕底部的正上方屏幕。

您可以通过使用UIView动画来实现动画效果:

// Pre OS4 way

[UIView beginAnimations:@"animName" context:NULL];
[UIView setAnimationDuration:0.2];

CGRect f = picker.frame;

if (showingPicker) {
f.origin.y = 480;
}
else {
f.origin.y = 480 - picker.frame.size.height;
}

picker.frame = f;

[UIView commitAnimations];

// Post OS4 way - Block based

[UIView animateWithDuration:0.2 animations:^{

if (showingPicker) {
f.origin.y = 480;
}
else {
f.origin.y = 480 - picker.frame.size.height;
}

picker.frame = f;

}

对于 DatePicker 输出,您可以使用 NSDateFormatter。您可以使用预定义的日期和时间样式或使用 setDateFormat:(NSString *)format 自行指定格式。

之后,您要做的就是调用 [formatter stringFromDate:datePicker.date];

关于iphone - 单击按钮时隐藏显示 UIPicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8432116/

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