Ios UIPickerView在子UIView中不工作

Ios UIPickerView在子UIView中不工作,ios,uipickerview,Ios,Uipickerview,我有一个UIPickerView,当放置在主视图上时,它可以完美地工作。但是,一旦我将其放置到子UIView中(以帮助直观地放置元素),交互就完全停止。UIPickerView仍然正确接收所有数据,只是没有交互 如果我使用故事板将UIPickerView从UIView中取出,它会立即工作 - (void)viewDidLoad { [super viewDidLoad]; // Add provinces into array [self.provinceView setH

我有一个UIPickerView,当放置在主视图上时,它可以完美地工作。但是,一旦我将其放置到子UIView中(以帮助直观地放置元素),交互就完全停止。UIPickerView仍然正确接收所有数据,只是没有交互

如果我使用故事板将UIPickerView从UIView中取出,它会立即工作

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Add provinces into array
  [self.provinceView setHidden:YES];
  isVisible = NO;
  self.provinceArray = [[NSArray alloc] initWithObjects:@"Alberta",@"British Columbia",@"Manitoba",@"New Brunswick",@"Newfoundland and Labrador",@"Northwest Territories",@"Nova Scotia",@"Nunavut",@"Ontario",@"Prince Edward Island",@"Quebec",@"Saskatchewan",@"Yukon",nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
  return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
  return [self.provinceArray count];
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0,(pickerView.frame.size.width-40), 44)];
  label.textColor = [UIColor colorWithRed:0.035 green:0.094 blue:0.345 alpha:1.0];
  label.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
  label.text = [self.provinceArray objectAtIndex:row];
  return label;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
  self.provinceLabel.text = [self.provinceArray objectAtIndex:row];
}
查看此帖子 -->


您是否将子视图置于前台?

您的子视图userInteractionEnabled=是吗?很抱歉,您发现了问题。由于某些原因,重新定位视图只是重新定位视图的内容。看起来我在解决CGRect问题时遇到了一个新问题。我使用了“边界”而不是“框架”来重新定位。