gpt4 book ai didi

ios - UIDatePicker 未显示在 UITable 上的正确位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:47:20 25 4
gpt4 key购买 nike

我有一个 UITableCell,在那个单元格上我有一个 UITextBox,当单击文本框而不是显示键盘时,会显示一个 UIDatePicker,代码如下。但我无法定位 UIDatePicker。我需要它从页面的最底部开始,此时它似乎是从按下文本框的表格部分的顶部开始的。当用户单击“首选日期”标签时,代码将触发。任何指针?我附上了一张图片以显示它当前渲染的位置。谢谢。

Issue

- (IBAction)selectDateBegin:(id)sender {


//Disable Keyboard
[self.txtBookingDate resignFirstResponder];
//Disable Scrolling
[_tableForm setScrollEnabled:false];

if ([self.view viewWithTag:9]) {
return;
}
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44);
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216);

UIView *darkView = [[UIView alloc] initWithFrame:self.view.bounds];
darkView.alpha = 0;
darkView.backgroundColor = [UIColor blackColor];
darkView.tag = 9;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissDatePicker:)] ;
[darkView addGestureRecognizer:tapGesture];
[self.view addSubview:darkView];

UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)] ;
datePicker.tag = 10;
[datePicker addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.tag = 11;
toolBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissDatePicker:)];
[toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
[self.view addSubview:toolBar];

[UIView beginAnimations:@"MoveIn" context:nil];
toolBar.frame = toolbarTargetFrame;
datePicker.frame = datePickerTargetFrame;
darkView.alpha = 0.5;
[UIView commitAnimations];
}

最佳答案

我建议您使用以下指令替换 textField 的 inputView(默认为键盘):

UIDatePicker *datePicker = [[UIDatePicker alloc] init] ;
[datePicker addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];

[preferredDateField setInputView:datePicker];

它更合适并且符合 Apple Human Interface Guideline

关于ios - UIDatePicker 未显示在 UITable 上的正确位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15310958/

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