2016-12-28 29 views
0

我試圖複製eBay iOS應用程序如何顯示其圖像,並允許用戶擴大每個圖像。如何在選擇時將UICollectionView單元展開爲屏幕寬度?

下面是它如何工作的:

enter image description here

易趣採用的是UICollectionView來顯示圖像的列表。當用戶選擇一個單元格時,單元格會隨着頂部的一些按鈕展開。當選中X時,單元格會摺疊回原始大小。

我該如何達到與此相似的目的?

我看過問題UICollectionView Enlarge cell on selectionExpanding UICollectionView and its cell when tapped,並試圖用我自己的想法實現它。

其中一個問題是我有AutoLayout設計,這使得這非常困難。

這是我的故事板:

enter image description here

我已經試過這樣:

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!) 
} 

而結果:

enter image description here

任何援助將大大有助於!

+3

那麼它不展開UICollectionView單元,但它彈出另一個控制器作爲模態與自定義過渡。您可能需要[此](https://github.com/michaelhenry/MHFacebookImageViewer) – iphonic

+0

如果您有多個圖像,請使用此https://github.com/zvonicek/ImageSlideshow。 – Nitesh

+0

正如@iphonic所提到的,我也認爲它並沒有擴展單元格。它只是一個具有自定義轉換的模式視圖控制器。如果你這樣做就會更容易。我並不是說不可能用細胞來做...但它會困難得多... – Seishin

回答

0

按照下面的步驟就可以實現這一點:

比方說你有兩個ViewControllers FirstViewController你在哪裏頂部有圖像和FullImageVC你在哪裏有中心形象。

  1. 編寫代碼來檢測點擊或將UIButton放在你的初始圖像上(上圖)。
  2. 關於該UIButton或點擊圖像動作的動作編寫一個邏輯模態呈現一個ViewController FullImageVC沒有動畫。
  3. FullImageVCviewWillAppear:你需要編寫邏輯兩兩件事:

首先

廣場上的FullImageVC類似上面的圖像,你已經把它放在一個FirstViewController並通過相同的圖像您點擊FirstViewController,然後編寫邏輯從頂部到中心對其進行動畫處理。

一旦完成動畫顯示您的CollectionView這將對所有的圖像,並顯示所選擇的一個。

4.放置十字按鈕並寫入其操作以解除FullImageVC

相關問題