2013-06-20 66 views
1

我有一個滾動視圖,其中包含約11個圖像和scrollView將只顯示在屏幕上的一個圖像。我需要通過圖像自動滾動圖像。我做了這樣的事情:是否可以通過設置contentOffset自動滾動?

[UIView animateWithDuration:120 
         delay:1 
        options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction 
       animations:^{   
        self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x+172*11,0); 

       } 
       completion:nil]; 

滾動視圖滾動通過所有的寬度其已經和我所看到的圖像之間的連接。是否可以通過設置contentOffset自動滾動?

感謝

+0

http://stackoverflow.com/questions/6354360/how -to-add-auto-scroll-functionality-to-a-view-in-iphone-sdk請找到這個鏈接..幫助 –

+0

我認爲使用'UIScrollView'setContentOffset:animated'消息會更容易'(帶定時器)而不是動畫塊。看到bhanu的解決方案,我沒有嘗試過,但看起來不錯。 –

+0

您也可以使用UIPageControl並使用定時器的「self.pageControl.currentPage = page」。 – stosha

回答

5

我做了我的UIScrollView自動滾動通過一套contentOffset這樣的:

[NSTimer scheduledTimerWithTimeInterval:.0 target:self selector:@selector(loadUrl) userInfo:nil repeats:NO]; 

- (void) loadUrl 
{ 
    currentOffset = scrlFirstScroll.contentOffset.y; 
    CGFloat newOffset = currentOffset + 3; 
    [scrlFirstScroll setContentOffset:CGPointMake(0.0,newOffset) animated:YES]; 
} 

希望這將有助於..

+0

我試了一下,它只是將第一張圖片滾動到第二張,我對此很陌生,我不知道如何讓圖片滾動到最後一張圖片。你能告訴我嗎? – Matin

相關問題