Sfoglia il codice sorgente

EditController: Have multiple cells in one line

Carola Nitz 6 anni fa
parent
commit
74d5a74d96
2 ha cambiato i file con 24 aggiunte e 1 eliminazioni
  1. 23 0
      Sources/MediaEditCell.swift
  2. 1 1
      Sources/VLCEditController.swift

+ 23 - 0
Sources/MediaEditCell.swift

@@ -115,6 +115,29 @@ class MediaEditCell: BaseCollectionViewCell {
         }
     }
 
+    override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
+        let numberOfCells: CGFloat
+        if width <= DeviceWidth.iPhonePortrait.rawValue {
+            numberOfCells = 1
+        } else if width <= DeviceWidth.iPhoneLandscape.rawValue {
+            numberOfCells = 2
+        } else if width <= DeviceWidth.iPadLandscape.rawValue {
+            numberOfCells = 3
+        } else {
+            numberOfCells = 4
+        }
+
+        // We have the number of cells and we always have numberofCells + 1 interItemPadding spaces.
+        //
+        // edgePadding-interItemPadding-[Cell]-interItemPadding-[Cell]-interItemPadding-edgePadding
+        //
+
+        let overallWidth = width - (2 * edgePadding)
+        let overallCellWidthWithoutPadding = overallWidth - (numberOfCells + 1) * interItemPadding
+        let cellWidth = floor(overallCellWidthWithoutPadding / numberOfCells)
+
+        return CGSize(width: cellWidth, height: height)
+    }
     override func prepareForReuse() {
         super.prepareForReuse()
         titleLabel.text = ""

+ 1 - 1
Sources/VLCEditController.swift

@@ -311,7 +311,7 @@ extension VLCEditController: UICollectionViewDelegateFlowLayout {
         if #available(iOS 11.0, *) {
             width = collectionView.safeAreaLayoutGuide.layoutFrame.width
         }
-        return CGSize(width: width - insetToRemove, height: MediaEditCell.height)
+        return MediaEditCell.cellSizeForWidth(width - insetToRemove)
     }
 }