一.數(shù)據(jù)不滿一屏?xí)r滑動(dòng)需開啟以下屬性
collectionView.alwaysBounceVertical=YES;// 垂直
collectionView.alwaysBounceHorizontal=YES;// 水平
二.刷新閃爍問題
1.用WithoutAnimation進(jìn)行刷新,僅IOS7+以上(建議使用)
[UIView performWithoutAnimation:^{
//刷新界面
[self.collectionView reloadData];
}];
2.performBatchUpdates僅支持刷新當(dāng)前變更的數(shù)據(jù)源,若調(diào)用reloadData刷新會(huì)報(bào)如下錯(cuò)誤:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (9) must be equal to the number of items contained in that section before the update (8), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out)
[UIView animateWithDuration:0 animations:^{
[collectionView performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
} completion:nil];
}];
[UIView animateWithDuration:0 animations:^{
[collectionView performBatchUpdates:^{
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
}];
3.同上
注:該方法使用不當(dāng)會(huì)造成UIview隱世動(dòng)畫消失
[UIView setAnimationsEnabled:NO];
[collectionView performBatchUpdates:^{
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:^(BOOL finished) {
[UIView setAnimationsEnabled:YES];
}];
以上方法都只針對UIView隱世動(dòng)畫
4.針對使用了CALayer的動(dòng)畫的取消刷新閃爍問題
[CATransaction begin];
[CATransaction setDisableActions:YES];
[collectionView reloadData];
[CATransaction commit];