2013-02-17 148 views
1

我正在開發一個在滾動視圖中顯示大量照片(約650張照片)的應用程序,爲了使此應用程序的功能順利進行,我在scrollView中只添加了三個UIImage,其中一個代表第一頁,第二頁爲當前頁面,第三頁爲下一頁,所以當用戶首次啓動應用程序時,第一個圖像將加載到中間頁面,最後一個圖像將加載到上一頁,第二個圖像將會加載到下一頁,當用戶向右滾動時,中間頁面將加載第二張圖片,上一頁將加載第一張圖片,下一頁將加載第三張圖片等。decelerationRate屬性不起作用

但是當用戶快速滾動滾動視圖的界限會出現,阻止用戶滾動到下一頁,只會博unce。

我的問題是如何使滾動視圖滾動速度更快,使-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 方法調用更快正常

我試圖decelerationRate屬性如下圖所示的代碼,但我沒有看到任何區別!我正確使用它還是有什麼問題?

在此先感謝

- (void)viewDidLoad 
{ 

    scrollView = [[ScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    scrollView.delegate = self; 
    //scrollView.decelerationRate= UIScrollViewDecelerationRateFast; 

    [self.view addSubview:scrollView]; 

    scrollView.contentSize = CGSizeMake(960, 416); 


    pageZero = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    pageOne = [[UIImageView alloc]initWithFrame:CGRectMake(320, 0, 320, 480)]; 
    pageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(640, 0, 320, 480)]; 


    //set array that holds images to be shown 
    for(int i = 0 ; i < 10 ; i++) 
     [pages addObject:[NSString stringWithFormat:@"%i.png",i]]; 

//load photos 
    [self loadPageWithId:0 onPage:1]; 
    [self loadPageWithId:2 onPage:0]; 
    [self loadPageWithId:1 onPage:2]; 

//add 3 UIImage objects to the scrollView 
    [scrollView addSubview:pageZero]; 
    [scrollView addSubview:pageOne]; 
    [scrollView addSubview:pageTwo]; 


    //scroll to the middle page without animation 
    [scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO]; 

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)]; 
    [self.scrollView addGestureRecognizer:singleTap]; 

} 

回答

0

如果你有一個pagingEnabled = YESUIScrollView,然後設置decelerationRate屬性將不會對頁面的速度產生任何影響(如你發現了)。

爲了解決這個問題,您需要設置pagingEnabled = NO並自己手動實現分頁功能。請參閱this question and answer瞭解如何操作。