gpt4 book ai didi

ios - 滚动tableview时编辑导航栏的alpha

转载 作者:行者123 更新时间:2023-12-01 17:20:25 24 4
gpt4 key购买 nike

我想问是否可以在用户滚动表格 View 时更改导航栏的 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);

最佳答案

可能为时已晚,但为了将来引用,您可以执行以下操作:

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

在这个委托(delegate)上,你有 scrollview 或 tableView 的 contentOffset 的值,你可以观察这个属性的值来做出你想要的行为。

希望能帮助到你!

关于ios - 滚动tableview时编辑导航栏的alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28274621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com