pujiaxin33 / JXPagingView

类似微博主页、简书主页等效果。多页面嵌套,既可以上下滑动,也可以左右滑动切换页面。支持HeaderView悬浮、支持下拉刷新、上拉加载更多。
MIT License
2.91k stars 565 forks source link

请问下JXPagingListContainerView如何滑动至指定的index #414

Closed Gaozn closed 3 months ago

Gaozn commented 2 years ago

我只使用了JXPagingListContainerView这个类。 我找到didClickSelectedItem这个方法,断点都会走,但是页面没任何反应 public func didClickSelectedItem(at index: Int) { guard checkIndexValid(index) else { return } willAppearIndex = -1 willDisappearIndex = -1 if currentIndex != index { listWillDisappear(at: currentIndex) listWillAppear(at: index) listDidDisappear(at: currentIndex) listDidAppear(at: index) } }

Gaozn commented 2 years ago

我尝试添加了这个方法来实现,不知道会不会有什么影响? public func didClickSelectedItem(at index: Int, without:Bool=true) { if without{ if self.type == .collectionView{ self.collectionView.scrollToItem(at: IndexPath(item: index, section: 0), at: .centeredVertically, animated: true) }else{ let sx = scrollView.bounds.size.width*CGFloat(index) scrollView.setContentOffset(CGPoint(x:sx, y: 0), animated: true) } } self.didClickSelectedItem(at: index) }

z234009184 commented 2 years ago

the same issue

J0nphy commented 1 year ago

同样的问题,这个需求很大啊!

roMummy commented 5 months ago

这样子 直接拿到contentScrollView 然后调用setContentOffset方法就行了 我这里用的是JXPagerListRefreshView JXPagingListContainerView应该也是一样的

- (void)switchSubPage:(NSInteger)index {
    UIScrollView *contentScrollView = self.pagerView.listContainerView.contentScrollView;
    CGPoint offset = CGPointMake(index*contentScrollView.bounds.size.width, 0);
    [contentScrollView setContentOffset:offset animated:true];

    [self.pagerView.listContainerView didClickSelectedItemAtIndex:index];
}
pujiaxin33 commented 3 months ago

可以通过segmentedView的func selectItemAt(index: Int)方法,实现选中某个index。OC版本就是categoryView的- (void)selectItemAtIndex:(NSInteger)index;方法