我想在用户向下滚动时根据其框架向 Scrollbar 添加一个视图。这已经由下面的自定义组件完成(直到 iOS 7 都可以正常工作)
https://github.com/honkmaster/TimeScroller
从 iOS 8 开始,从 UitableView 访问 Scrollbar 的框架似乎发生了很多变化。
- (void)captureTableViewAndScrollBar
{
_tableView = [self.delegate tableViewForTimeScroller:self];
self.frame = CGRectMake(CGRectGetWidth(self.frame) - 10.0f, 0.0f, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
for (UIView *subview in [_tableView subviews]){
if ([subview isKindOfClass:[UIImageView class]] && subview.tag == 0){
NSLog(@"check this SubViews %@ and its Tag %ld",subview , (long)subview.tag);
UIImageView *imageView = (UIImageView *)subview;
if (imageView.frame.size.width == 7.0f || imageView.frame.size.width == 5.0f || imageView.frame.size.width == 3.5f
|| imageView.frame.size.height == 2.5f){
imageView.clipsToBounds = NO;
[imageView addSubview:self];
_scrollBar = imageView;
_saved_tableview_size = _tableView.frame.size;
break;
}
}
}
}
以上是确定Tableview的ScrollBar Frame的代码块
基于上面的矩形,我们形成要添加的视图的矩形,并通过以下代码找到对应的 TableviewCell
CGRect selfFrame = self.frame;
CGRect scrollBarFrame = _scrollBar.frame;
NSLog(@"Check this %@",_scrollBar);
self.frame = CGRectMake(CGRectGetWidth(selfFrame) * -1.0f,
(CGRectGetHeight(scrollBarFrame) / 2.0f) - (CGRectGetHeight(selfFrame) / 2.0f),
CGRectGetWidth(selfFrame),
CGRectGetHeight(_backgroundView.frame));
CGPoint point = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
point = [_scrollBar convertPoint:point toView:_tableView];
UIView *view = [_tableView hitTest:point withEvent:nil];
问题:当用户滚动 tableView 时,ScrollBar 框架 Y 似乎没有发生变化,因此 hitTest 无法找到 TableViewCell
请找到 TableView > 的示例 ScrollBar 框架及其 Tag 0
我需要一些有关如何在 iOS 8.1 版本上完成相同操作的帮助