Hello!

Such a problem, there is a UIPickerView , on the central line (the line that is highlighted), a button is added, when clicked, an event occurs, but if you start scrolling UIPickerView from the button, the scrolling does not work. How to fix it?

    1 answer 1

    Found a solution. Removed the button and added UITapGestureRecognizer . Link to the answer .

    Add UITapGestureRecognizer

     UITapGestureRecognizer *tapToSelect = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappedToSelectRow:)]; tapToSelect.delegate = self; [self.pickerView addGestureRecognizer:tapToSelect]; 

    We process pressing:

     #pragma mark - Actions - (IBAction)tappedToSelectRow:(UITapGestureRecognizer *)tapRecognizer { if (tapRecognizer.state == UIGestureRecognizerStateEnded) { CGFloat rowHeight = [self.pickerView rowSizeForComponent:0].height; CGRect selectedRowFrame = CGRectInset(self.pickerView.bounds, 0.0, (CGRectGetHeight(self.pickerView.frame) - rowHeight) / 2.0 ); BOOL userTappedOnSelectedRow = (CGRectContainsPoint(selectedRowFrame, [tapRecognizer locationInView:self.pickerView])); if (userTappedOnSelectedRow) { // Тут выполняем нужное действие } } } 

    And do not forget about:

     #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return true; } 
    • @ D-side fixed. Thank! - Vitali Eller