【发布时间】:2015-07-10 16:25:06
【问题描述】:
我有两个 nib 文件,分别是 RowRecordLayout 和 ColumnLayout。
我确实将笔尖单元格注册到 UICollectionView 以便稍后在 cellForItemAtIndexPath 函数中使用。这是我的代码
override func viewDidLoad() {
self.DJCollectionView.registerNib(UINib(nibName: "RowTemplateCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "DJCELL")
self.DJCollectionView.registerNib(UINib(nibName: "ColumnTemplateCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "DJCELL2")
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath
indexPath: NSIndexPath) -> UICollectionViewCell {
var ProductCardCellpt : DJCell?
if self._CurrentLayoutType == enum_Layout.RowRecords {
reuseIdentifier = "DJCELL"
ProductCardCellpt = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as? DJCell
…
}else{
reuseIdentifier = "DJCELL2"
ProductCardCellpt = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as? DJCell
...
}
return ProductCardCellpt!
}
最后当我触摸 DJ 按钮时。除了单元格内的意外约束之外,过渡之间的动画还可以
这是Transition布局的代码
@IBAction func Action_ToggleLayout(sender: UIBarButtonItem) {
if _CurrentLayoutType == enum_Layout.TwoColumn {
_CurrentLayoutType = enum_Layout.RowRecords
self.DJCollectionView.setCollectionViewLayout(self._RowRecordsLayout_CollectionViewLayout!, animated: true, completion: { (IsDone) -> Void in
})
}
else{
_CurrentLayoutType = enum_Layout.TwoColumn
self.DJCollectionView.setCollectionViewLayout(self._TwoColumnLayout_CollectionViewLayout!, animated: true, completion: { (IsDone) -> Void in
}
})
}
}
当我向上或向下滚动时,单元格内的内容恢复正常。 有什么解决办法吗?
【问题讨论】:
-
你可以把collectionView布局放在nib文件中吗?您只能将 UICollectionViewCell 放在 nib 中,不是吗?
-
它们是 nib 中的 UICollectionViewCell。
-
你什么时候改变了你的collectionView的布局?
-
触摸 DJ 按钮时布局发生变化。我已经编辑了我的帖子以包含更改布局代码。
标签: ios objective-c swift