2011-11-03 83 views
1

我有一個水平的scrollView其中包含2個圖像。scrollView是circular.What我想要做的是幾秒鐘後設置自動滾動。任何想法我怎麼能做到這一點?水平scrollView幾秒鐘後自動滾動

我試過如下:

[UIScrollView beginAnimations:@"scrollAnimation" context:nil]; 
    [UIScrollView setAnimationDuration:5]; 
    [UIScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0)]; 
    [UIScrollView commitAnimations]; 

但這:[UIScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0)];不recognized.Any想法感謝

回答

1

做這樣的事情:-)

[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(onTimer) userInfo:nil repeats:YES]; 

    - (void) onTimer { 

     // Updates the variable h, adding 100 (put your own value here!) 
     h += 100; 

     //This makes the scrollView scroll to the desired position 
     yourScrollView.contentOffset = CGPointMake(0, h); 

    } 
1

你誤解了動畫聲明語法 我們建議,你有你的滾動視圖引用在你的代碼如下:

UIScrollView *scrollView = ...; // it must have a reference to the actual scroll view instance 
... 
[UIView beginAnimations: @"scrollAnimation" context:nil]; 
[UIView setAnimationDuration: 5.0f]; 

[scrollView setContentOffset:CGPointMake(x,y)]; 

[UIView commitAnimations]; 

這應該爲你工作