andreamazz / AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
MIT License
6.05k stars 633 forks source link

UITableViewController "out of box" install yields black gap #44

Closed dmur closed 10 years ago

dmur commented 10 years ago

Hi, thanks for this great library. :+1:

I couldn't find any documentation on using the project with UITableViewController, and when I use it with a table view controller "out of the box":

[self followScrollView:self.tableView]

there is a 64px gap added to the frame as soon as I start scrolling.

  1. How do I get rid of that gap?
  2. Since this is likely the most common integration scenario, it seems like documentation should exist for this.
dmur commented 10 years ago

This is definitely a hack, but I currently solve this problem as follows:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  // Prevent the AMScrollingNavbar from creating a black gap the first time the feed is scrolled.
  if (scrollView.contentOffset.y > 0
      && CGRectGetMinY(self.tableView.frame) != 0) {
    CGRect frameAdjustedToPreventOffset = self.tableView.frame;
    frameAdjustedToPreventOffset.size.height += frameAdjustedToPreventOffset.origin.y;
    frameAdjustedToPreventOffset.origin.y = 0;
    self.tableView.frame = frameAdjustedToPreventOffset;
  }
}
andreamazz commented 10 years ago

Hi @dmur The implementation is independent from the type of scrollview you want to attach it to, that's why there's no specific documentation for the tableview (in any case, the sample project shows the implementation for it).
you just need to call

[self followScrollView:self.tableView]

making sure that your navbar is not translucent.
The gap you are referring to might be an old issue that is now fixed in the latest version (that I'm waiting to push to cocoapods until I iron out a couple of issues), and you can get it by setting the :head symbol in your podfile, like so:

pod 'AMScrollingNavbar, :head'

I hope this helps.
Cheers

dmur commented 10 years ago

Thanks for that. Unfortunately, updating to the head commit does not resolve the issue for me, I still need to use the workaround above to avoid the black gap. It's not a navigation bar translucency issue, mine is opaque.

FWIW, I wasn't sure if UITableViewController was supported because the example "AMTableViewController" is actually a UIViewController subclass. Perhaps that's the difference here.

andreamazz commented 10 years ago

Yep, you're right, it's probably the UITableViewController.
The AMTableViewController is a UIVIewController because I rarely use UITableViewControllers, since I like to have control over the view's hierarchy, and that's a good example of why I do that.
The current implementation of the scrollingnavbar requires that the scrollable view is contained in another view, and that's not the case with the UITableViewController.
I'll see if I can work around this and release an update.
Thanks for your feedback!

andreamazz commented 10 years ago

After some tinkering I can safely say that it can't be done. When you try to resize the tableview, the infamous black bar appears. It happens even if you resize the table manually.
That's why I never use a UITableViewController, it's just too limited and always a pain. You should too stick with a plain UIViewController and add a UITableView yourself.

dmur commented 10 years ago

@andreamazz I tried switching to UIViewController, but when the navigation bar is contracted, I get an extra 44px space at the bottom of the table. I'm guessing this is because AMScrollingNavbar doesn't change the view's frame when it contracts the nav bar (i.e. intended behavior)? Or is this a bug? Thanks

andreamazz commented 10 years ago

Did you set the bottom constraint on your table to hug the bottom of its superview?

dmur commented 10 years ago

Yeah, I set the constraints as defined in the README (0 for all sides).

andreamazz commented 10 years ago

Hi @dmur I made a quick video on how to implement the library in a UIViewController with a UITableView: https://vimeo.com/92721470
If you are still experiencing this issue, please let me know how does your setup differ from the one in the video.

dmur commented 10 years ago

Hey, cheers on the video -- loved the music :)

Unfortunately I couldn't tell if the example in the video has the same issue as I'm describing or not. The problem would be visible if, after integrating the scrolling navbar, when you scroll to the bottom of the table, there is a gap == 44px (because the frame of the table view no longer extends to the bottom of its superview).

Our setup is different in that we have a tab bar at the bottom. However I've a few minutes now, so I'll go ahead and replicate your example and then confirm whether or not that setup demonstrates the same issue.

dmur commented 10 years ago

Actually, looks like this is unrelated to this project, just has to do with using UITableView within a UIViewController that's embedded in a tab bar. To fix I just had to redo the constraints after adding the view controller relationship to the tab bar. Sorry for the trouble.

andreamazz commented 10 years ago

No trouble at all. I'm glad it's working.
Cheers

ghost commented 10 years ago

I'm also getting the black bar when using a UITableViewController (I have to use a UITableViewController) – I have read the comments above but can't understand how to resolve the issue, can you advise @dmur @andreamazz ? Thank you

dmur commented 10 years ago

@dawson See my ugly hack above to work around the black bar, in the second post. Just use that implementation for your scrollViewDidScroll in the UITableViewController (it's a UIScrollViewDelegate as well, since UITableViewDelegate inherits from UIScrollViewDelegate), and it should remove the black bar. However, also note that I have not used that code in production, and it could have some unintended bugs!