前言
现在标签分页横向滚动控制器很普遍,自己写原生的需要一些细节注意。
我们都知道一次请求不要太多,所以按照滚动到某处位置在显示加载就很有必要。
image.png
代码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
int index = floor((scrollView.contentOffset.x - SCREEN_WIDTH / 2) / SCREEN_WIDTH) + 1;
self.topView.selectIndex = index;
if (index < self.store.homeMenuArray.count) {
LiveHomeMenuModel *model = self.store.homeMenuArray[index];
NSString *title = model.name;
if ([title isEqualToString:@"视频"]) {
self.publishButton.hidden = YES;
}else {
self.publishButton.hidden = NO;
}
if ([title isEqualToString:@"秘密"]){
self.publishButton.selected = YES;
}else {
self.publishButton.selected = NO;
}
UIViewController *vc = self.itemControllerArray[index];
if (!vc.isViewLoaded) {
vc.view.frame = CGRectMake(SCREEN_WIDTH *index, 0, SCREEN_WIDTH, self.contentHeight);
[self.scrollView addSubview:vc.view];
[self addChildViewController:vc];
}
}
}
网友评论