【发布时间】:2016-08-01 12:11:39
【问题描述】:
我在 SingleView 上有 UITableView。表格视图有约束左0,右0,底部0,顶部520。向上滚动时我需要将顶部520更改为0,向下滚动时返回520。如何做到这一点。
如何从滚动中更改NSLayoutConstraint -
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
我试图实现这样但失败了
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.tag == 1){
if (scrollView.contentOffset.y < pointNow.y) {
self.heightLogTabTableView.constant = 0;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}else if (scrollView.contentOffset.y > pointNow.y) {
self.heightLogTabTableView.constant = 520;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}
}
}
【问题讨论】:
-
创建一个 TopSpace 约束的出口,并根据需要更改其在 scrollView 委托中的常量值。
-
相反,使用 indexPath 跟踪
willDisplayCell或CellForRowAtIndexPath代表中的滚动,并根据行或部分执行适当的操作 -
@NSNoob UITableView 继承自 UIScrollView
-
这意味着 UIScollView 的委托方法应该可以工作
-
@NSNoob scrollView 父表视图,我认为实现这一点。
标签: ios objective-c uitableview uiscrollview nslayoutconstraint