当我用多个组件制作一个长选择器时,只有靠近中心的组件才会对点击选择功能做出反应。
例如,如果您想选择选定行下的下一行,您应该只需点击它即可使其动画进入选择区域。此功能在 iOS 7 中仍然存在,但 UIPicker 中实际接受点击的区域是一个非常小的窗口,不大于 200 像素。
有什么方法可以扩展这个可点击区域以包含整个 UIPickerView,所以只要您点击一行,它就会成为选择?
编辑这里是代码,它很标准......
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"picked %i %i" , component , row);
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 4;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 15;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return @"";
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *pickersLabel;
pickersLabel =[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, view.frame.size.width , view.frame.size.height )];
pickersLabel.text = [NSString stringWithFormat:@"thing %i" , row ];
pickersLabel.backgroundColor = [UIColor clearColor];
pickersLabel.backgroundColor = [UIColor colorWithRed:1/255.0 green:1/255.0 blue:2/255.0 alpha:0.05];
pickersLabel.opaque = NO;
[view addSubview:pickersLabel];
return pickersLabel;
}