12207480 / TYCyclePagerView

a simple and usefull cycle pager view ,and auto scroll banner view(轮播图) ,include pageControl for iOS,support Objective-C and swift
MIT License
1.8k stars 331 forks source link

reloadData 之后直接调用 scrollToItemAtIndex 无效问题 #26

Closed Connerli closed 6 years ago

Connerli commented 6 years ago
-(void)loadData {
    NSMutableArray *datas = [NSMutableArray array];
    for (int i = 0; i < 7; ++i) {
        if (i == 0) {
            [datas addObject:[UIColor redColor]];
            continue;
        }
        [datas addObject:[UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:arc4random()%255/255.0]];
    }
    _datas = [datas copy];
    _pageControl.numberOfPages = _datas.count;
    [_pagerView reloadData];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
         [_pagerView scrollToItemAtIndex:3 animate:YES];
    });

}

当我初始化数据完成,想要滚动到指定的index,这时候调用scrollToItemAtIndex 失效,因为layoutSubviews 时候重置了contentOffset,目前是加了个延迟,但是路子有点野,请问有更好的方式没有?

12207480 commented 6 years ago

[_pagerView reloadData]; [_pagerView scrollToItemAtIndex:3 animate:YES]; 直接设置

Connerli commented 6 years ago

@12207480 demo 里面也很容易复现的,直接设置是不行的。

12207480 commented 6 years ago

好的 我看看

12207480 commented 6 years ago

已修复