listview和gridview之间的快速ios切换
我刚进入ios swift,现在正在尝试在listview和更大的listview之间切换 我现在拥有的是一个普通的listview。我想做的是创建一个按钮,在listview和“更大”的listview之间切换,例如在Instagram中的每个列表项中创建更大的图像listview和gridview之间的快速ios切换,ios,swift,Ios,Swift,我刚进入ios swift,现在正在尝试在listview和更大的listview之间切换 我现在拥有的是一个普通的listview。我想做的是创建一个按钮,在listview和“更大”的listview之间切换,例如在Instagram中的每个列表项中创建更大的图像 这是通过创建两个独立的ViewController来实现的吗?您的问题一点也不清楚。 很明显,通过两个ViewControllers执行以下操作,可以创建该视图 将选定对象传递到下一个视图的序列。 或者,如果您使用的是滚动视图,则
这是通过创建两个独立的ViewController来实现的吗?您的问题一点也不清楚。 很明显,通过两个ViewControllers执行以下操作,可以创建该视图 将选定对象传递到下一个视图的序列。
或者,如果您使用的是滚动视图,则可以使用现有的缩放方法(zoomToRect) 我所做的是让2 UIButton与主collectionview类中的2 func连接,如下所述
// Use to define whether displaying grid view or block view
// useful when you use nib files for cells (see the 3rd code example)
// true by default
var isGridView = true
loadGridView () {
isGridView = true
collectionView?.performBatchUpdates({
// load or setup for gridlayout
}, completion: nil)
collectionView?.reloadData()
}
及
例如,您可以访问
!!!如果您正在为单元格使用nib,则需要注册所有nib,并且它的类也需要知道
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell:UICollectionViewCell
if(isGridView) {
let gridCell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath) as! CustomGridViewCellClass
// some setup
cell = gridCell
} else {
let blockCell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath) as! CustomBlockViewCellClass
// some setup
cell = blockCell
}
return cell
}
什么是列表视图?什么是网格视图?你想干什么?@nhgrif为我拙劣的解释感到抱歉。我的意思是这样的:我现在的问题是,实现这一目标的“正确/恰当”方式是什么?对不起,我解释得不好。我的意思是:我现在的问题是,实现这一目标的“正确/适当”方式是什么?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell:UICollectionViewCell
if(isGridView) {
let gridCell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath) as! CustomGridViewCellClass
// some setup
cell = gridCell
} else {
let blockCell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath) as! CustomBlockViewCellClass
// some setup
cell = blockCell
}
return cell
}