瀏覽代碼

local network: tap twice on navbar for show or hide search bar

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Pierre SAGASPE 10 年之前
父節點
當前提交
63fcaf1103

+ 19 - 1
Sources/VLCLocalPlexFolderListViewController.m

@@ -106,7 +106,12 @@
     _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
     _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
     _searchBar.delegate = self;
-    self.tableView.tableHeaderView = _searchBar;
+    //self.tableView.tableHeaderView = _searchBar;
+    //self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(_searchBar.frame)); // -> hide search bar to load
+
+    UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwiceGestureAction:)];
+    [tapTwiceGesture setNumberOfTapsRequired:2];
+    [self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture];
 
     // Active le Pull down to refresh
     _refreshControl = [[UIRefreshControl alloc] init];
@@ -399,4 +404,17 @@
     [self performSelector:@selector(reloadTableViewPlex) withObject:nil];
 }
 
+#pragma mark - Gesture Action
+
+- (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
+{
+    _searchBar.hidden = !_searchBar.hidden;
+    if (_searchBar.hidden)
+        self.tableView.tableHeaderView = nil;
+    else
+        self.tableView.tableHeaderView = _searchBar;
+
+    [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
+}
+
 @end

+ 17 - 1
Sources/VLCLocalServerFolderListViewController.m

@@ -160,7 +160,10 @@
     if (SYSTEM_RUNS_IOS7_OR_LATER)
         _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
     _searchBar.delegate = self;
-    self.tableView.tableHeaderView = _searchBar; //this line add the searchBar on the top of tableView.
+
+    UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwiceGestureAction:)];
+    [tapTwiceGesture setNumberOfTapsRequired:2];
+    [self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture];
 
     _searchData = [[NSMutableArray alloc] init];
     [_searchData removeAllObjects];
@@ -777,4 +780,17 @@
     tableView.backgroundColor = [UIColor blackColor];
 }
 
+#pragma mark - Gesture Action
+
+- (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
+{
+    _searchBar.hidden = !_searchBar.hidden;
+    if (_searchBar.hidden)
+        self.tableView.tableHeaderView = nil;
+    else
+        self.tableView.tableHeaderView = _searchBar;
+
+    [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
+}
+
 @end

+ 3 - 0
Sources/VLCPlaylistViewController.m

@@ -709,6 +709,9 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
             self.tableView.tableHeaderView = nil;
         else
             self.tableView.tableHeaderView = _searchBar;
+
+        [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
+
     } else
         [self setupContentViewWithContentInset:YES];
 }