2010-11-03 8 views
4

J'ai scrollView avec pagingScrollView.pagingEnabled = YES;. Après avoir secoué légèrement à la page suivante, le ScrollView rebondit un peu après décélérer, voici mon journal origin.x changer avec des commentaires:UIScrollView rebondit un peu après la décélération

2010-11-03 12:53:09.187 app[84864:207] scrollview.bound.origin.x: 713.000000 << deccelerating.. 
2010-11-03 12:53:09.199 app[84864:207] scrollview.bound.origin.x: 727.000000 
2010-11-03 12:53:09.212 app[84864:207] scrollview.bound.origin.x: 738.000000 
2010-11-03 12:53:09.230 app[84864:207] scrollview.bound.origin.x: 747.000000 
2010-11-03 12:53:09.248 app[84864:207] scrollview.bound.origin.x: 754.000000 
2010-11-03 12:53:09.262 app[84864:207] scrollview.bound.origin.x: 759.000000 
2010-11-03 12:53:09.278 app[84864:207] scrollview.bound.origin.x: 763.000000 
2010-11-03 12:53:09.295 app[84864:207] scrollview.bound.origin.x: 766.000000 
2010-11-03 12:53:09.312 app[84864:207] scrollview.bound.origin.x: 768.000000 <<at this origin.y, should stop deccelerating 
2010-11-03 12:53:09.328 app[84864:207] scrollview.bound.origin.x: 769.000000 <<bounce ? 
2010-11-03 12:53:09.377 app[84864:207] scrollview.bound.origin.x: 770.000000 <<bounce ? 
2010-11-03 12:53:09.378 app[84864:207] scrollview.bound.origin.x: 769.000000 <<bounce ? 
2010-11-03 12:53:09.395 app[84864:207] scrollview.bound.origin.x: 768.000000 <<stopped 

Comment cela pourrait-il arriver? La largeur du cadre est de 768px.

Répondre

4

J'ai le même problème. Désactiver le rebond ne fait rien.

UPD:

Je ne sais pas encore - pourquoi est-ce qui se passe. J'ai vérifié l'échantillon PhotoScroller d'Apple, et cette chose se passe aussi là. J'ai trouvé cette solution de contournement - peut-être il est pas tout à fait bien, mais cela fonctionne:

  1. J'attends cet événement à occure:

    -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; 
    

puis mettre juste la bonne position du contenu:

CGFloat pageWidth = pagingScrollView.bounds.size.width; 
NSInteger curPage = currentPage; 

if (firstTapPoint.x > lastTapPoint.x) { 
    //NSLog(@"Going prev page"); 
    curPage = (curPage==0)?0:(currentPage-1); 
}else if(firstTapPoint.x < lastTapPoint.x){ 
    //NSLog(@"Going next page"); 
    curPage = (currentPage==([self imageCount]-1))?currentPage:(currentPage+1); 
}else if(firstTapPoint.x == lastTapPoint.x) { 
    //NSLog(@"Staying on the same page");  
} 

//NSLog(@"Current page is %d and the next page is %d", currentPage, curPage); 

CGPoint finalOffset = CGPointMake(pageWidth * curPage, 0); 
[scrollView setContentOffset:finalOffset animated:YES]; 

alors la vue de défilement défile droit à la position I spécifiée, sans aucune «queue rebondissement

+0

Merci. Cela m'a aidé à résoudre le problème. Juste comment obtenir le firstTapPoint ant lastTapPoint. – negersiu

+0

C'est assez simple. Vous pouvez implémenter - (void) scrollViewWillBeginDragging: (UIScrollView *) méthode scrollView delegate, et là vous pouvez obtenir le premier point de tap: firstTapPoint = CGPointMake (scrollView.contentOffset.x, 0); Ensuite, vous pouvez implémenter une autre méthode déléguée - (void) scrollViewWillBeginDecelerating: (UIScrollView *) scrollView; Ici vous pouvez obtenir le dernier point de tap: lastTapPoint = CGPointMake (scrollView.contentOffset.x, 0); – deMouton

Questions connexes