【发布时间】:2016-11-22 13:26:06
【问题描述】:
我想在一个 UIViewController 中添加三个视图,
- UIImageView
- 可滚动段控件 (HMSegmentedControl)
- UIViews(或)UITableviewCells
当整个视图滚动时,段控件应该固定在屏幕顶部(如 UITableview 中的标题)。
我的代码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ((long)scrollView.tag == 10) {
// Main scrollview
if (self.lastContentOffset >= scrollview.contentOffset.y) {
NSLog(@"Down");
if (scrollview.contentOffset.y < 158.0f) {
[scrollview setContentOffset:CGPointMake(scrollview.contentOffset.x, scrollview.contentOffset.y)];
[matchInfoTable setScrollEnabled:NO];
[scrollview setScrollEnabled:YES];
}
} else if (self.lastContentOffset <= scrollview.contentOffset.y) {
NSLog(@"Up");
NSLog(@"%f",scrollview.contentOffset.y);
if (scrollview.contentOffset.y > 138.0f) {
[scrollview setScrollEnabled:NO];
[matchInfoTable setScrollEnabled:YES];
}
if (scrollview.contentOffset.y >= 163.0f) {
[scrollview setContentOffset:CGPointMake(scrollview.contentOffset.x, 163.0f)];
[scrollview setScrollEnabled:NO];
[matchInfoTable setScrollEnabled:YES];
}
}
self.lastContentOffset = scrollview.contentOffset.y;
NSLog(@"LastOffset :: %f",self.lastContentOffset);
} else if (scrollView.tag == MATCH_INFO) {
// match info table
if (scrollView.contentOffset.y == 0) { // TOP
[scrollview setContentOffset:CGPointMake(scrollview.contentOffset.x, scrollview.contentOffset.y)];
[matchInfoTable setScrollEnabled:NO];
[scrollview setScrollEnabled:YES];
}
}
}
在这段代码中当段控制引脚位于顶部。下面的视图没有连续滚动。我需要再次触发它的滚动。
感谢所有答案!
【问题讨论】:
标签: ios objective-c uitableview uiview uiscrollview