Vấn đề của tôi là một superset của vấn đề này - Tôi đã có UISliders bên UITableViewCells và cả UITableView là một trang bên trong một UIScrollView. Các thanh trượt đã tàn phá các tương tác với hai loại kia và các giải pháp phân lớp không hoạt động. Dưới đây là những gì tôi đã đưa ra đó là làm việc tuyệt vời: gửi thông báo khi thanh trượt di chuyển và có UITableView và UIScrollView disableScrolling trên trong thời gian này. Lưu ý trong hình dưới đây: thanh trượt của tôi là ngang, tableview của tôi là dọc, và UIScrollView của tôi có các trang nằm ngang.

Các UITableViewCell nhặt các sự kiện cho thanh trượt lập trình tạo:
self.numberSlider = [[UISlider alloc] init];
[self.numberSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.numberSlider addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];
[self.numberSlider addTarget:self action:@selector(sliderTouchUp:) forControlEvents:UIControlEventTouchUpInside];
[self.numberSlider addTarget:self action:@selector(sliderTouchUp:) forControlEvents:UIControlEventTouchUpOutside];
Theo mục đích của hướng dẫn này, chúng tôi chỉ quan tâm đến Touchdown và Up:
- (void)sliderTouchDown:(UISlider *)sender
{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFY_SLIDER_TOUCH_BEGAN object:nil];
}
- (void)sliderTouchUp:(UISlider *)sender
{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFY_SLIDER_TOUCH_ENDED object:nil];
}
Bây giờ, chúng tôi nắm bắt các thông báo này trong cả UITableView (lưu ý rằng tableview là trong VC nhưng tôi chắc chắn điều này sẽ làm việc nếu bạn subcl assed):
- (void)viewDidLoad
{
// other stuff
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sliderTouchDown:) name:NOTIFY_SLIDER_TOUCH_BEGAN object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sliderTouchUp:) name:NOTIFY_SLIDER_TOUCH_ENDED object:nil];
}
- (void)sliderTouchDown:(NSNotification *)notify
{
self.treatmentTableView.scrollEnabled = NO;
}
- (void)sliderTouchUp:(NSNotification *)notify
{
self.treatmentTableView.scrollEnabled = YES;
}
và UIScrollView (tương tự như trên, kèm theo trong một VC):
- (void)viewDidLoad
{
// other stuff
// Register for slider notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disableScrolling:) name:NOTIFY_SLIDER_TOUCH_BEGAN object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableScrolling:) name:NOTIFY_SLIDER_TOUCH_ENDED object:nil];
}
- (void)disableScrolling:(NSNotification *)notify
{
self.scrollView.scrollEnabled = NO;
}
- (void)enableScrolling:(NSNotification *)notify
{
self.scrollView.scrollEnabled = YES;
}
Tôi muốn nghe một giải pháp thanh lịch hơn, nhưng điều này chắc chắn được hoàn thành công việc . Khi bạn sử dụng một thanh trượt, bảng và các cuộn xem vẫn giữ nguyên và khi bạn nhấp vào bên ngoài thanh trượt, các xem bảng và cuộn sẽ di chuyển như mong đợi. Ngoài ra - lưu ý rằng tôi có thể sử dụng các phiên bản không thuộc lớp con của tất cả 3 thành phần trong giải pháp này. Hy vọng điều này sẽ giúp một ai đó!
Nguồn
2014-01-22 00:43:16
Cảm ơn, đã kết thúc với điều đó. Tuy nhiên, một sự kỳ quặc khác ... hành vi này dường như chỉ xuất hiện trên giả lập. Một khi tôi đã nhận nó trên thiết bị nó làm việc tốt mà không cần sửa chữa. – MarkPowell
Thú vị, lý do khác không chỉ dựa vào giả lập để kiểm tra ... – BoltClock
FWIW, tôi thấy chính xác hành vi tương tự (như được mô tả trong câu hỏi gốc) trên cả trình mô phỏng (iOS 6) và thiết bị (iOS 5.1). Tôi phải chạm và giữ một lúc trước khi kéo thanh trượt, nếu không tôi sẽ nhận được chế độ xem cuộn cuộn thay thế. –