iOS 为什么添加在ScrollView上的button在我滑动ScrollView后, button的点击事件就失效了滑动时,控制台打印如下:
-[UIScrollView(UIScrollViewInternal) _offsetForRubberBandOffset:maxOffset:minOffset:range:] detected range=(newOffset - maxOffset), returning input unmodified

解决方案 »

  1.   

    在ScrollView上的button是怎么添加的?循环添加还是还是手动添加?多个button是用什么区分的tag?这些个我们都不知道,贴出代码来啊
      

  2.   

    看看滑动后,button位置是否还在scrollview上没。
      

  3.   

     _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, 35)];
        CGFloat btnWidth = WIDTH/5;
        _scrollView.backgroundColor = [UIColor lightGrayColor];
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(btnWidth*15, 0);    [_scrollView setContentOffset:CGPointMake(0,0) animated:YES];    [self.view addSubview:_scrollView];代理方法:
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {    if (scrollView == _scrollView) { // 如果此时滑动的是_scrollView,避免影响tableView的滑动
            if (scrollView.contentOffset.y < 0) {
                scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
            }
            
            if (scrollView.contentOffset.y > 0) {
                scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
            }
            
            
        }
        
    }    for (int i = 0;  i < 15; i++) {
            UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(i*btnWidth, 0, btnWidth, 30)];
            [btn setTitle:arr[i] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            btn.userInteractionEnabled = YES;        btn.tag = i + btn_tag;
            [_scrollView addSubview:btn];
        }
      

  4.   

    (不好意思,忙其他的去了。晚上又弄了一会,还是不行)不写代理方法,button的点击是可以的,但是button显示不在ScrollView的顶部,调用scrollToTop没用。
    写了代理方法后,button显示正常且禁止了上下滑动。但是在ScrollView滑动后,button点击不响应,且控制台有如下打印:
    -[UIScrollView(UIScrollViewInternal) _offsetForRubberBandOffset:maxOffset:minOffset:range:] detected range=(newOffset - maxOffset), returning input unmodified
      

  5.   

    Help Me!!!!!
      

  6.   

    你的scrollView是怎么添加的啊?
      

  7.   

    - (void)viewDidLoad {
        [super viewDidLoad];
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, 135)];
        CGFloat btnWidth = WIDTH/5;
        _scrollView.backgroundColor = [UIColor lightGrayColor];
        _scrollView.showsVerticalScrollIndicator = YES;
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake((btnWidth + 10)*15, 0);
        
        [_scrollView setContentOffset:CGPointMake(0,0) animated:YES];
        
        [self.view addSubview:_scrollView];
        
        for (int i = 0;  i < 15; i++) {
            UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(i*(btnWidth + 10), 0, btnWidth, 30)];
            [btn setTitle:[NSString stringWithFormat:@"%d",i+100] forState:UIControlStateNormal];
            NSInteger armc4number = arc4random() %256;
            btn.backgroundColor = [UIColor colorWithRed:armc4number/255.0 green:armc4number/255.0 blue:armc4number/255.0 alpha:1.0];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.tag = i;
            [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            btn.userInteractionEnabled = YES;
            [_scrollView addSubview:btn];
        }
    }
    -(void)btnClicked:(UIButton *)sender{
        UIButton *a = sender;
        NSInteger count = a.tag;
        NSLog(@"**************%ld***************",(long)count);
    }
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        
        if (scrollView == _scrollView) { // 如果此时滑动的是_scrollView,避免影响tableView的滑动
            if (scrollView.contentOffset.y < 0) {
                scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
            }
            
            if (scrollView.contentOffset.y > 0) {
                scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
            }
            
            
        }
        
    这样写是可以的啊,你坑定是别的地方埋了坑
      

  8.   

    个人觉得  是button在  scrollViewDidScroll这个协议方法里面创建 有点 问题 楼主 你为何不先创建好 然后触发 scrollViewDidScroll这个函数的时候 再让它显示呢? 而且你在滑动 的时候创建 这是非常不对的 当你不断的触发滑动 的方法的时候你会发现你创建了很多button
      

  9.   

    楼主解决了吗-(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
      

  10.   

    楼主解决了吗-(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
      

  11.   

    滑动后偏移量改变,button不在原来位置。