Преглед на файлове

correctly resize collectionview cells on different devices

Carola Nitz преди 9 години
родител
ревизия
2f079e32c3
променени са 1 файла, в които са добавени 11 реда и са изтрити 4 реда
  1. 11 4
      Sources/VLCLibraryViewController.m

+ 11 - 4
Sources/VLCLibraryViewController.m

@@ -781,10 +781,17 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
 
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
 {
-    if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
-        return CGSizeMake(341., 190.);
-    else
-        return CGSizeMake(384., 216.);
+    const CGFloat maxCellWidth = 300.0;
+    const CGFloat aspectRatio = 9/16;
+
+    CGRect windowFrame = [UIApplication sharedApplication].keyWindow.frame;
+    CGFloat windowWidth = windowFrame.size.width;
+
+    int numberOfCellsPerRow = ceil(windowWidth/maxCellWidth);
+    CGFloat cellWidth = windowWidth/numberOfCellsPerRow;
+
+    return CGSizeMake(cellWidth, cellWidth * aspectRatio);
+
 }
 
 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section