我遇到了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];
答案 0 :(得分:0)
问题是UIDatePicker
超出了UIActionSheet
的范围,如果你设置了
menu.clipsToBounds = YES;
为了适当调整大小,请将帧大小调整代码更改为
CGRect pickerRect = tmpPickerView.frame;
CGRect menuRect = menu.frame;
pickerRect.origin.y = menuRect.size.height;
menuRect.size.height = menuRect.size.height + pickerRect.size.height;
menuRect.origin.y = menuRect.origin.y - pickerRect.size.height;
menu.frame = menuRect;
tmpPickerView.frame = pickerRect;