简体   繁体   English

UIViewController中的表视图不具有hidesBarsOnSwipe功能

[英]Table view in UIViewController doesn't get hidesBarsOnSwipe functionality

I have a table view as the first child of a regular UIViewController. 我有一个表视图作为常规UIViewController的第一个子视图。 I've tried adding the navigation controller's barHideOnSwipeGestureRecognizer gesture recognizer to both my view and table view, but no dice. 我尝试将导航控制器的barHideOnSwipeGestureRecognizer手势识别器添加到我的视图和表格视图中,但是没有骰子。 In the snippet below, blah: is never getting called. 在下面的代码段中,blah:从未被调用。

[self.navigationController setHidesBarsOnSwipe:YES];
[self.tableView addGestureRecognizer:self.navigationController.barHideOnSwipeGestureRecognizer];
[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(blah:)];

I feel like the barHideOnSwipeGestureRecognizer is the way to tap into this nice functionality when not using a top level scroll view controller (collection or table), but I can't figure out exactly how. 我觉得当不使用顶级滚动视图控制器(集合或表)时, barHideOnSwipeGestureRecognizer是利用此barHideOnSwipeGestureRecognizer功能的方法,但我无法确切知道如何实现。

If you want to hide navigationbar on swipe, meaning when you scroll your tableview in upward direction (goes to down) then 如果您想在滑动时隐藏navigationbar栏,这意味着当您向上滚动tableview (向下滚动)时,

 self.navigationController.hidesBarsOnSwipe = YES;

is enough to achieve this. 足以实现这一目标。 It will hide the navigationbar and show it again on tap . 它将隐藏navigationbar并在tap时再次显示。 Make sure you have set proper constraint to tableview . 确保为tableview设置了适当的约束。 your constraint should be top,bottom,leading and trailing with constant of 0 with nearest neighbor . 您的约束应该是top,bottom,leading and trailing且常数为0且与nearest neighbor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM