我正在寻找一种在向下滚动 UITableView 时将 UINavigationBar titleView alpha channel 减少到零并在向上滚动时执行相反操作的方法。
使用 scrollViewDidScroll 委托(delegate)有什么干净的方法吗?
最佳答案
super 简单,只需将其放入导航 Controller 中的 TableView Controller 中:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.navigationController.navigationBar.alpha = 1 - (self.tableView.contentOffset.y / (self.tableView.contentSize.height - self.tableView.frame.size.height));
}
减
self.tableView.frame.size.height
是因为 contentOffset
从顶部设置,因此即使在最低位置也会被框架的宽度分开; 0-100 范围是 0 到 ( contentSize.height
- frame.size.height
)。
关于iOS - 如何在滚动 UITableView 时减少 UINavigationBar titleView 的 alpha?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28549935/