美文网首页
UICollectionView scrollToItemAtI

UICollectionView scrollToItemAtI

作者: Yo_Moon | 来源:发表于2017-08-09 17:33 被阅读0次

解决方法1:前面加上layoutIfNeeded

[self loadViewIfNeeded];

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.currentIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];

解决方法2:viewDidLayoutSubviews

- (void)viewDidLayoutSubviews {

[super viewDidLayoutSubviews];

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.currentIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];

}

相关文章

网友评论

      本文标题:UICollectionView scrollToItemAtI

      本文链接:https://www.haomeiwen.com/subject/qlyqrxtx.html