如题,如何让scrollview能自动滑动,不用手触就可以自己循环滑动

解决方案 »

  1.   

    起个定时器  里边用setContentOffset
      

  2.   


    我加了定时器了,但是他只是从自动滑动到2,之后就不在自动滑动了,需要我手触
       NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.25
                                                          target:self
                                                        selector:@selector(handleTimer:)
                                                        userInfo:nil
                                                         repeats:NO]; 
    - (void) handleTimer: (NSTimer *) timer
    {
        
        [scrollView setContentOffset:CGPointMake(320, 0) animated:YES];      
    }
      

  3.   

    CGPointMake(320, 0)把坐标设置成变量,每次在促发定时器的时候为这个变量上加一个特定的值,如果超过了你设定的最大值就归0就可以了啊
      

  4.   


    我加了个循环啊,还是第一页滚动
    - (void) handleTimer: (NSTimer *) timer
    {
        for (unsigned j=320; j<pNum; j++) {
            [scrollView setContentOffset:CGPointMake(j, 0) animated:YES];
        }
              
    }
      

  5.   

    别在定时器里放循环啊~假设 你的pNum = 2000你该在定时器里写if (xPoint > 2000)
          xPoint = 0xPoint += 320[scrollView setContentOffset:CGPointMake(xPoint, 0) animated:YES]; 然后定时器的时间间隔长一点
      

  6.   

    ......打log看下xPoint的值的变化规律
      

  7.   

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.25
                                                          target:self
                                                        selector:@selector(handleTimer:)
                                                        userInfo:nil
                                                         repeats:YES];
      

  8.   

    repeats:NO   改成 repeats:YES
      

  9.   

    设置定时器,不断改变scrollview的位置,ok