【发布时间】:2018-03-06 13:34:28
【问题描述】:
我有一个视图控制器,顶部是页面视图控制器,底部是表格视图。当我向上滚动表格视图时,我希望表格视图框架在我向下滚动时向上滑动到屏幕顶部并返回到页面控制器视图的底部。
- 表格视图向上滑动到屏幕顶部,但表格视图单元格也会滚动。请参阅第一个视频链接。
我只想改变框架并滚动表格视图单元格直到它到达屏幕顶部。
video similar to what I want to achieve
在我的示例中,我尝试更改附加到 scrollViewDidScroll 中表格视图顶部的 NSLayoutConstraint。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//the height of the pageview controller
//the height and width of the pageview controller is the screen width.
CGFloat yPos = self.pageViewHolder.frame.size.height;
//content offset as I scroll
CGFloat offset = self.tableView.contentOffset.y;
//to place the tableview exactly below pageview controller view
if (offset < 0) {
offset = screenSize.height - screenSize.width;
}
//to place the tableview frame fixed on top of the screen
else if (offset > yPos) {
offset = screenSize.width;
}
//to slide the table view above page view by changing the NSLayoutConstraint anchored to the top of the table view and the super view.
CGFloat difference = yPos - offset;
self.tableViewTopGap.constant = difference;
[self.view layoutIfNeeded];
}
【问题讨论】:
-
你为什么不把tableView作为一个子视图放在后台,然后添加PanGesture呢?
标签: ios objective-c iphone uitableview uipageviewcontroller