Swi*_*per 6 ios uicollectionview swift
我有工作uicollectionview
代码CustomCollectionViewLayout
,内部有,a lot of small cells
但用户无法看到它们zoom
.所有细胞也可选择.
我想在缩放功能中添加我的集合视图!
我的明确代码如下.
class CustomCollectionViewController: UICollectionViewController {
var items = [Item]()
override func viewDidLoad() {
super.viewDidLoad()
customCollectionViewLayout.delegate = self
getDataFromServer()
}
func getDataFromServer() {
HttpManager.getRequest(url, parameter: .None) { [weak self] (responseData, errorMessage) -> () in
guard let strongSelf = self else { return }
guard let responseData = responseData else {
print("Get request error \(errorMessage)")
return
}
guard let customCollectionViewLayout = strongSelf.collectionView?.collectionViewLayout as? CustomCollectionViewLayout else { return }
strongSelf.items = responseData
customCollectionViewLayout.dataSourceDidUpdate = true
NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
strongSelf.collectionView!.reloadData()
})
}
}
}
extension CustomCollectionViewController {
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return items.count
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items[section].services.count + 1
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionViewCell
cell.label.text = items[indexPath.section].base
return cell
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath cellForItemAtIndexPath: NSIndexPath) {
print(items[cellForItemAtIndexPath.section].base)
}
}
Run Code Online (Sandbox Code Playgroud)
另外我UICollectionView
在下面的布局属性你可以看到我选择maxZoom 4
但doesnt
有任何行动!
谢谢 !
您不会像缩放简单的滚动视图那样缩放集合。相反,您应该添加捏合手势(或其他缩放机制)并使用它来更改布局,以便网格在集合的可见部分中显示不同数量的项目。这基本上改变了列数,从而改变了项目大小(单元格大小)。当您更新布局时,集合可以在不同尺寸之间进行动画处理,尽管您不太可能想要平滑缩放,但您希望它一步直接从 N 列变为 N-1 列。