0

I would like to add a view to Scrollbar based on its frame as user scrolls down. This is already being done by below custom component (works fine till iOS 7)

https://github.com/honkmaster/TimeScroller

From iOS 8 there seems to be lot of changes in accessing the frame of Scrollbar from UitableView.

- (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;
        }
    }
}
}

Above is the code block to determine the ScrollBar Frame of Tableview

Based on the above rect we form the rect for view to be added and find the Corresponding TableviewCell by below code

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];

Issue : ScrollBar frame Y didn't seems to be changing as user scrolls the tableView and hence hitTest fails to find the TableViewCell

Please find the sample ScrollBar frame of TableView > and its Tag 0

I need some help on How to accomplish the same on iOS 8.1 Version

Sundar_Mob
  • 155
  • 12
  • So this code is going through the subviews of a table view to try and find the scroll bar, by finding the first image view with no tag and a special size? This is exactly the kind of thing that breaks between iOS versions. You're depending on a private implementation detail. – jrturton Oct 24 '14 at 06:42
  • did you meant to say "captureTableViewAndScrollBar" method is failing to find the scrollbar ? If yes , Could you please tell me how i can determine the Scrollbar from Uitableview – Sundar_Mob Oct 24 '14 at 07:12
  • Well, you're not supposed to. That's kind of my point. Any time you use code that does private view walking like this you expose yourself to that kind of risk. – jrturton Oct 24 '14 at 11:12
  • Okay then is there any other way i can attach a label to right of cell floating on the UItableView as user scrolling the tableview – Sundar_Mob Oct 24 '14 at 11:17
  • Issue resolved by changing the above method on mentioned library – Sundar_Mob Oct 29 '14 at 13:53

1 Answers1

0

Issue is Resolved by changing the above method as mentioned below on the same library

- (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]]){
            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.width == 2.5f || (imageView.width < 2.5f && imageView.width > 2.3 && [[AppUtils deviceModelName] isEqualToString:kIPHONE6PLUS])){
                imageView.clipsToBounds = NO;
                [imageView addSubview:self];
                _scrollBar = imageView;
                _saved_tableview_size = _tableView.frame.size;
                break;
            }
        }
    }
}
Sundar_Mob
  • 155
  • 12