viewController
由2个主要视图组成。容器视图和表视图。
容器视图是包含所有标签的顶部部分,例如日期和分数。
我希望在用户开始滚动表视图的日子时隐藏此容器视图。
到目前为止,我有:
IBOutlet
,以便我可以在代码中引用它。UIScrollViewDelegate
UITableView
我知道UITableView
是UIScrollView
的子类。没有“正确的”UIScrollView
我很困惑如何使用scrollViewDidScroll
方法并在我在tableView中滚动时将容器视图alpha更改为0.
当用户停止滚动时,我也希望alpha返回1.
感谢。
注意我没有使用UITableViewController
答案 0 :(得分:5)
您应该使用UITableViewController而不是UIViewController,然后在UITable的标题部分中拖动UIView。这将导致UIView在开箱即用时完全滚动,完全没有编码。
答案 1 :(得分:2)
如果您已经将 UITableViewDelegate IBOutlet设置为控制器,您将从 UITableView 以及所有 UIScrollViewDelegate 方法接收所有UITableViewDelegate方法,你实现它们。
如果您想在用户开始滚动时隐藏特定视图,我会使用 -scrollViewWillBeginDragging 方法
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
[UIView animateWithDuration:0.5f animations:^{
someView.alpha = 0.0f;
}];
}
如果您想在用户停止滚动后再次显示它,只需使用方法 -scrollViewDidEndDragging:willDecelerate:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
[UIView animateWithDuration:0.5f animations:^{
someView.alpha = 1.0f;
}];
}
答案 2 :(得分:1)
直接在控制器中使用以下方法。他们会工作:
// called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
答案 3 :(得分:1)
你做了什么UIScrollViewDelegate?
我刚刚在当前项目中使用了UITableViewController并添加了UIScrollViewDelegate
@interface YourTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate>
然后在
中发表评论- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
并根据需要调用一次(scrollViewDidScroll:将重复触发)。所以我假设调用一个UIView animateWithDuration:方法将完成你需要的任务?