1
我有一個帶有2個單元格的小集合視圖。這是垂直屏幕上的中心。當用戶選擇一個單元格時,一個新的單元格出現在集合視圖中,並且集合視圖相應地改變它的插入單元到屏幕中垂直中間的3個單元格。然而這種變化並不順利,它很跳躍。有沒有什麼方法來動畫collectionView插入更改?collectionView Insets中的動畫更改
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray* array = [super layoutAttributesForElementsInRect:rect];
UICollectionViewLayoutAttributes* att = [array lastObject];
if (att){
CGFloat lastY = att.frame.origin.y + att.frame.size.height;
CGFloat diff = self.collectionView.frame.size.height - lastY;
if (diff > 0){
UIEdgeInsets contentInsets = UIEdgeInsetsMake(diff/2, 0.0, 0.0, 0.0);
self.collectionView.contentInset = contentInsets;
}
self.diff = diff;
}
return array;
}