UIPickerView 的日期仅向一个方向旋转
我在使用 UIPickerView 时遇到了奇怪的行为:
我试图在操作表中显示日期选择器。 一切正常,除了轮子一开始只向一个方向旋转!
如果您开始向上旋转并将方向更改为向下 - 它会起作用。但是当您尝试开始向下旋转时,拾取器不会移动。
这是我的代码:
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker"
delegate:self
cancelButtonTitle:@"Abbrechen"
destructiveButtonTitle:nil
otherButtonTitles:@"Auswählen",nil];
// Add the picker
UIDatePicker *tmpPickerView = [[UIDatePicker alloc] init];
tmpPickerView.datePickerMode = UIDatePickerModeDate;
[tmpPickerView addTarget:self
action:@selector(pickerChanged:)
forControlEvents:UIControlEventValueChanged];
[menu addSubview:tmpPickerView];
[menu showInView:self];
CGRect menuRect = menu.frame;
menuRect.origin.y -= 214;
menuRect.size.height = 300;
menu.frame = menuRect;
CGRect pickerRect = pickerView.frame;
pickerRect.origin.y = 174;
pickerView.frame = pickerRect;
[tmpPickerView release];
[menu release];
I am experiencing a strange behavior with a UIPickerView:
I am trying to show an Date Picker within an action sheet.
Everything works well, except that the wheels are only rotating in one direction at first!
If you start rotating up and change the direction to down - it works. But when you try to start rotating down, the picker won't move.
Here is my code:
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker"
delegate:self
cancelButtonTitle:@"Abbrechen"
destructiveButtonTitle:nil
otherButtonTitles:@"Auswählen",nil];
// Add the picker
UIDatePicker *tmpPickerView = [[UIDatePicker alloc] init];
tmpPickerView.datePickerMode = UIDatePickerModeDate;
[tmpPickerView addTarget:self
action:@selector(pickerChanged:)
forControlEvents:UIControlEventValueChanged];
[menu addSubview:tmpPickerView];
[menu showInView:self];
CGRect menuRect = menu.frame;
menuRect.origin.y -= 214;
menuRect.size.height = 300;
menu.frame = menuRect;
CGRect pickerRect = pickerView.frame;
pickerRect.origin.y = 174;
pickerView.frame = pickerRect;
[tmpPickerView release];
[menu release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
UIDatePicker
超出了UIActionSheet
的范围,如果设置menu.clipsToBounds = YES;
,您可以看到它为了适当地调整大小,请将框架调整大小代码更改为
The problem is that the
UIDatePicker
is extending beyond the bounds of theUIActionSheet
, which you can see if you setmenu.clipsToBounds = YES;
In order to resize things appropriately, change your frame resizing code to