滚动tableview时编辑导航栏的alpha

Mic*_*ués 1 xcode scroll objective-c uinavigationbar ios

我想询问当用户滚动tableview时是否可以更改导航栏的alpha值.

我有算法,但我需要一些帮助来实时更改.

  /* This is the offset at the bottom of the scroll view. */
CGFloat totalScroll = scrollView.contentSize.height - scrollView.bounds.size.height;

/* This is the current offset. */
CGFloat offset = - scrollView.contentOffset.y;

/* This is the percentage of the current offset / bottom offset. */
CGFloat percentage = offset / totalScroll;

/* When percentage = 0, the alpha should be 1 so we should flip the percentage. */
scrollView.alpha = (1.f - percentage);
Run Code Online (Sandbox Code Playgroud)

Ren*_*cki 7

这可能为时已晚,但为了将来参考,你可以这样做:

 func scrollViewDidScroll(scrollView: UIScrollView) {
     self.navigationController!.navigationBar.alpha = 1 - (self.tableView.contentOffset.y / (self.tableView.contentSize.height - self.tableView.frame.size.height));
 }
Run Code Online (Sandbox Code Playgroud)

在此委托上,您具有scrollview或tableView的contentOffset的值,您可以观察此属性的值以实现所需的行为.

希望能帮助到你!