滚动横线实现逻辑:
1.使用kvo监听scrollView
[self.scroll addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
2.设置
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"contentOffset"]) {
CGFloat distance =CGRectGetMinX(self.offline.frame) - CGRectGetMinX(self.online.frame);
CGFloat x = CGRectGetMinX(self.online.frame) - 4 + (self.scroll.contentOffset.x *(distance / HCUIScreen.size.width));
self.lineView.frame = CGRectMake(x, self.lineY, self.lineW, 1);
}
}