【问题标题】:Customizing UIView class with UIScrollview and UITableview使用 UIScrollview 和 UITableview 自定义 UIView 类
【发布时间】:2016-11-22 13:26:06
【问题描述】:

我想在一个 UIViewController 中添加三个视图,

  1. UIImageView
  2. 可滚动段控件 (HMSegmentedControl)
  3. 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


    【解决方案1】:

    我认为你最好使用 UIPageViewController 并放入所有 tableviews 中,然后你可以检测滑动和更改选项卡。

    您还可以使用 UISwipeGestureRecognizer 并检测本文left and right swipes

    中描述的左右滑动

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多