我試圖複製eBay iOS應用程序如何顯示其圖像,並允許用戶擴大每個圖像。如何在選擇時將UICollectionView單元展開爲屏幕寬度?
下面是它如何工作的:
易趣採用的是UICollectionView
來顯示圖像的列表。當用戶選擇一個單元格時,單元格會隨着頂部的一些按鈕展開。當選中X時,單元格會摺疊回原始大小。
我該如何達到與此相似的目的?
我看過問題UICollectionView Enlarge cell on selection和Expanding UICollectionView and its cell when tapped,並試圖用我自己的想法實現它。
其中一個問題是我有AutoLayout設計,這使得這非常困難。
這是我的故事板:
我已經試過這樣:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let cell = collectionView.cellForItem(at: indexPath)
cell?.superview?.bringSubview(toFront: cell!)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
self.structureImageView.frame = CGRect(x: 0, y: 0, width: 375, height: 667)
collectionView.frame = self.structureImageView.bounds
cell?.frame = collectionView.bounds
self.separatorView.frame.origin.y = 667
self.structureInfoView.frame.origin.y = 667
}), completion: nil)
test = true
collectionView.reloadData()
}
var test = false
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
if test == true
{
return CGSize(width: 375, height: 667)
}
return CGSize(width: cellWidth!, height: cellHeight!)
}
而結果:
任何援助將大大有助於!
那麼它不展開UICollectionView單元,但它彈出另一個控制器作爲模態與自定義過渡。您可能需要[此](https://github.com/michaelhenry/MHFacebookImageViewer) – iphonic
如果您有多個圖像,請使用此https://github.com/zvonicek/ImageSlideshow。 – Nitesh
正如@iphonic所提到的,我也認爲它並沒有擴展單元格。它只是一個具有自定義轉換的模式視圖控制器。如果你這樣做就會更容易。我並不是說不可能用細胞來做...但它會困難得多... – Seishin