我想滾動集合視圖一些屏幕外的細胞沒有動畫和滾動後,得到該小區的位置。問題是收集視圖正確滾動(直觀),但單元格框架保持離屏。這裏是我的代碼:UICollectionView scrollToItemAtIndexPath:買新鮮細胞位置
NSIndexPath *path = [fetchedResultsController indexPathForObject:objectInCollection];
[collectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
[collectionView layoutSubviews]; // or 'layoutIfNeeded', doesn't matter
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:path];
cellFrame = [cell.superview convertRect:cell.frame toView:nil]; // still not refreshed
我可以建議收集視圖不適用於滾動,所以我想找到應用滾動的方法。
--- --- UPDATE
收集視圖是在先前的視圖控制器(因此我從代碼滾動它然後彈出可見視圖控制器)。
電池框架,即使在先前的視圖控制器viewDidAppear:
方法保持屏幕外。確切地說,[cell.superview convertRect:cell.frame toView:nil];
返回幀集合視圖沒有contentOffset
。因此CGRectOffset([cell.superview convertRect:cell.frame toView:nil], 0, -collectionView.contentOffset.y)
會在屏幕上返回正確的單元格框架。
我不知道我是否正確理解了您的問題,但即使在滾動後,您也應該爲單元格獲取相同的幀。滾動不會改變子視圖的框架;只有contentOffset應該改變。 或者你是否想要在UICollectionView的超視圖座標中獲取框架? –