我希望与iPhone联系人应用程序中的生日日期设置器具有相同的效果。如何让模式日期选择器只出现在屏幕的一半位置。
我希望日期选择器在UITableView上(就像在iphone联系人应用程序中)。我希望UITableView可以在日期选择器后面自由滚动(就像在iphone联系人应用程序中一样)。
提前谢谢。
发布于 2011-12-21 08:22:58
到目前为止,实现类似日期选择器/uipicker键盘的最佳方法是使用文本字段的输入视图属性:
@ }
txtTextField.inputView =dtpPicker;
行inComponent:(NSInteger)component:(UIPickerView*)行didSelectRow:(NSInteger)pickerView didSelectRow
祝好运!埃拉德。
发布于 2011-12-23 02:08:24
这就是我如何实现它的:我将UIDatePicker放在一个名为DateTimeEntryViewController的不同控制器中,当用户单击按钮/单元格以引入日期和时间时,我在UIViewController中执行以下代码:
self.alphaView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.alphaView.opaque = NO;
self.alphaView.backgroundColor = [UIColor clearColor];
self.dateTimeEntryViewController.view.backgroundColor = [UIColor clearColor];
UIWindow *window = [[TTNavigator navigator] window];
[window addSubview:self.alphaView];
[window insertSubview:self.dateTimeEntryViewController.view aboveSubview:self.alphaView];
CGRect r = [_dateTimeEntryViewController.view frame];
r.origin.y = 480.0f;
[self.dateTimeEntryViewController.view setFrame:r];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5f];
self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
r.origin.y = 0;
[self.dateTimeEntryViewController.view setFrame:r];
[UIView commitAnimations];因此,我基本上展示了视图控制器,它将UIDatePicker放在当前UIDatePicker的顶部。
发布于 2011-12-24 02:14:40
这段代码将添加一个日期选择器作为UITableView的子视图。这段代码假设我们是UITableViewController的子类。
我们将从底部开始设置拾取器的动画。最后,我们将挂钩到scrollViewDidScroll: delegate方法,以便在表格滚动时,选择器看起来保持不动。
在.h文件中,为选取器添加一个属性。
@property (strong, nonatomic) UIDatePicker *datePicker;在您的.m文件中,我们添加了日期选择器。
- (void)viewDidLoad
{
// Your own customization code.
self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 200, 320, 216)];
self.datePicker.hidden = YES;
[self.datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.datePicker];
}
- (void)presentDatePicker
{
if (self.datePicker.hidden == NO) { return; }
// Set the date picker frame to be below the screen.
self.datePicker.frame = CGRectMake(0, self.view.frame.size.height, self.datePicker.size.width, self.datePicker.size.height);
CGRect originFrame = self.datePicker.frame;
// Animate from the bottom.
[UIAnimation animateWithDuration:.3 animations^{
self.datePicker.frame = CGRectMake(0, 200, originFrame.size.width, originFrame.size.height);
}];
}
#pragma mark - Scroll view delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect tableBounds = self.tableView.bounds;
CGRect datePickerFrame = self.datePicker.frame;
self.datePicker.frame = CGRectMake(0, 200 + tableBounds.origin.y, datePickerFrame.size.width, datePickerFrame.size.height);
}别忘了@综合你的属性并在viewDidUnload上发布它
https://stackoverflow.com/questions/8484147
复制相似问题