【发布时间】:2015-04-05 01:48:12
【问题描述】:
我正在尝试创建一个可以手动调整大小的集合视图。
collectionView 内的单元格具有屏幕的宽度和集合视图的高度。
除了当用户更改集合视图高度时单元格不更新约束之外,我已经完成了整个工作。它们仅在出现新单元格时才会更新
我尝试了不同的方法来使这个高度直接动画,但似乎没有解决方案可以立即改变单元格高度和集合视图高度。
是否有一种解决方法可以使单元格大小在大小上具有动画效果?
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let width = self.CollectionViewController2.frame.width as CGFloat
let height = self.CollectionViewController2.frame.height as CGFloat
return CGSizeMake(self.CollectionViewController2.frame.width, self.CollectionViewController2.frame.height)
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CustomCell = collectionView.dequeueReusableCellWithReuseIdentifier("demoCell", forIndexPath: indexPath) as CustomCell
let height = self.CollectionViewController2.frame.height
cell.frame = CGRectMake(cellB.frame.origin.x, 0, cellB.frame.size.width, height)
cell.updateConstraintsIfNeeded()
cell.layoutIfNeeded()
cell.imgs.image = UIImage(named: somePictures[indexPath.row])
return cell
}
一个允许滑动手势调整集合视图大小的按钮:
@IBAction func SwipeDownStatus(sender: AnyObject) {
if CollectionViewHeight.constant == 390 {
self.CollectionViewHeight.constant = 130
self.CommentLikeBarHeight.constant = -50
CollectionViewController2.updateConstraints()
UIView.animateWithDuration(0.25, animations: { () -> Void in
self.view.layoutIfNeeded()
})
}
【问题讨论】:
标签: ios swift animation cell collectionview