I want to do something like the keyboard show/hide so I want to set up picker as a first responder. Is this possible. If not how can i show/hide UIPicker in a view by a button click. On other topic how can i format the DatePicker output, now i get "2011-12-8 23:00 000000"
我想做一些像键盘显示/隐藏的东西,所以我想把选择器设置为第一响应者。这可能吗。如果不是如何通过按钮单击在视图中显示/隐藏UIPicker。关于其他主题我如何格式化DatePicker输出,现在我得到“2011-12-8 23:00 000000”
2 个解决方案
#1
1
You could have your UIPicker below your sceen (say, y = 480 for iPhone), and then when you tap your button move it to 480 - picker.frame.size.height so that it shows right above the bottom of your screen.
你可以将你的UIPicker放在你的下方(例如,iPhone的y = 480),然后当你点击按钮时将其移动到480 - picker.frame.size.height,使其显示在屏幕底部的正上方。
You can achieve the animated effect by using UIView animations as:
您可以使用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;
}
And for the DatePicker output you can use an NSDateFormatter. You can use predefined date and time styles or use setDateFormat:(NSString *)format to specify the format yourself.
对于DatePicker输出,您可以使用NSDateFormatter。您可以使用预定义的日期和时间样式,也可以使用setDateFormat:(NSString *)格式自行指定格式。
After that all you do is call your [formatter stringFromDate:datePicker.date];
之后你要做的就是调用[formatter stringFromDate:datePicker.date];
#2
#1
1
You could have your UIPicker below your sceen (say, y = 480 for iPhone), and then when you tap your button move it to 480 - picker.frame.size.height so that it shows right above the bottom of your screen.
你可以将你的UIPicker放在你的下方(例如,iPhone的y = 480),然后当你点击按钮时将其移动到480 - picker.frame.size.height,使其显示在屏幕底部的正上方。
You can achieve the animated effect by using UIView animations as:
您可以使用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;
}
And for the DatePicker output you can use an NSDateFormatter. You can use predefined date and time styles or use setDateFormat:(NSString *)format to specify the format yourself.
对于DatePicker输出,您可以使用NSDateFormatter。您可以使用预定义的日期和时间样式,也可以使用setDateFormat:(NSString *)格式自行指定格式。
After that all you do is call your [formatter stringFromDate:datePicker.date];
之后你要做的就是调用[formatter stringFromDate:datePicker.date];