Browse Source

iOS: Add collectionView landscape orientation for phones

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Soomin Lee 8 years ago
parent
commit
e09a270638
2 changed files with 31 additions and 16 deletions
  1. 28 16
      Sources/VLCLibraryViewController.m
  2. 3 0
      Sources/VLCMovieViewController.m

+ 28 - 16
Sources/VLCLibraryViewController.m

@@ -97,6 +97,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
 - (void)loadView
 {
     [self setupContentViewWithContentInset:NO];
+    [self setViewFromDeviceOrientation];
     [self updateViewsForCurrentDisplayMode];
     _libraryMode = VLCLibraryModeAllFiles;
 
@@ -152,21 +153,18 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
         [contentView addSubview:_collectionView];
         [_collectionView reloadData];
     }
-
-    if (setInset) {
-        CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
-        // Status bar frame doesn't change correctly on rotation
-        CGFloat statusBarHeight = MIN(statusBarSize.height, statusBarSize.width);
-        CGFloat originY = self.navigationController.navigationBar.frame.size.height + statusBarHeight;
-
-        UIScrollView *playlistView = self.usingTableViewToShowData ? _tableView : _collectionView;
-        playlistView.contentInset = UIEdgeInsetsMake(originY, 0, 0, 0);
-    }
     self.view = contentView;
 }
 
 #pragma mark -
 
+- (void)viewWillLayoutSubviews {
+    UIScrollView *dataView = self.usingTableViewToShowData ? _tableView : _collectionView;
+
+    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
+    [dataView setContentInset:UIEdgeInsetsZero];
+}
+
 - (void)viewDidLoad
 {
     [super viewDidLoad];
@@ -243,6 +241,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     _searchBar.delegate = self;
 
     [self setSearchBar:YES resetContent:YES];
+    self.edgesForExtendedLayout = UIRectEdgeNone;
 
     @synchronized (self) {
         _searchData = [[NSMutableArray alloc] init];
@@ -488,10 +487,22 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
     [self updateViewsForCurrentDisplayMode];
 }
 
-- (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent
+- (void)setViewFromDeviceOrientation
 {
-    self.tableView.tableHeaderView = enable ? _searchBar : nil;
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+        UIDevice *currentDevice = [UIDevice currentDevice];
+        BOOL isPortrait = UIDeviceOrientationIsPortrait(currentDevice.orientation);
 
+        [self setUsingTableViewToShowData:isPortrait];
+    }
+}
+
+- (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent
+{
+    if (enable)
+        self.tableView.tableHeaderView = _searchBar;
+    else
+        self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, CGFLOAT_MIN)];
     if (resetContent) {
         CGPoint contentOffset = self.tableView.contentOffset;
         contentOffset.y += CGRectGetHeight(self.tableView.tableHeaderView.frame);
@@ -846,7 +857,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
 
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
 {
-    const CGFloat maxCellWidth = 300.0;
+    const CGFloat maxCellWidth = [UIScreen mainScreen].bounds.size.width / 3;
     const CGFloat aspectRatio = 9.0/16.0;
 
     CGRect windowFrame = [UIApplication sharedApplication].keyWindow.frame;
@@ -854,19 +865,19 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
 
     int numberOfCellsPerRow = ceil(windowWidth/maxCellWidth);
     CGFloat cellWidth = windowWidth/numberOfCellsPerRow;
+    cellWidth -= 5;
 
     return CGSizeMake(cellWidth, cellWidth * aspectRatio);
-
 }
 
 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
 {
-    return UIEdgeInsetsZero;
+    return UIEdgeInsetsMake(5, 5, 5, 5);
 }
 
 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
 {
-    return 0.;
+    return 2.5;
 }
 
 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
@@ -1662,6 +1673,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
 {
     [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
 
+    [self setViewFromDeviceOrientation];
     if (self.usingTableViewToShowData) {
         NSArray *visibleCells = [self.tableView visibleCells];
         NSUInteger cellCount = visibleCells.count;

+ 3 - 0
Sources/VLCMovieViewController.m

@@ -34,6 +34,7 @@
 #import "VLCStatusLabel.h"
 #import "VLCMovieViewControlPanelViewController.h"
 #import "VLCSlider.h"
+#import "VLCLibraryViewController.h"
 
 #define FORWARD_SWIPE_DURATION 30
 #define BACKWARD_SWIPE_DURATION 10
@@ -1592,6 +1593,8 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
     [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+
+        [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate libraryViewController] willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
         if (self.artworkImageView.image)
             self.trackNameLabel.hidden = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);