scrollViewWillEndDragging:
メソッドを使用して、App Store アプリと同様に、両側にプレビューを表示して独自のページ化された UICollectionView をロールしようとしています。ただし、スクロールビューの下のコードを使用すると、慣性なしでドラッグを停止した場合 (つまり、指を離すだけ)、目的の四角形にのみスクロールします。慣性でフリックしてもメソッドは呼び出されますが、スクロールビューは目的の四角形をスクロールせず、スクロールし続けますか?
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset
{
int itemWidth = 280;
MyCollectionView *collectionView = (MyIndexedCollectionView *) scrollView;
int totalPages = [self.colorArray[collectionView.index] count];
int currentPage;
int nextPage;
if (lastContentOffset < (int)scrollView.contentOffset.x)
{
// moved right
NSLog(@"scrolling right");
double currentPageOffset = ceil((scrollView.contentSize.width -
scrollView.contentOffset.x) / itemWidth);
currentPage = totalPages - currentPageOffset;
nextPage = currentPage >= totalPages ? totalPages : currentPage + 1;
}
else if (lastContentOffset > (int)scrollView.contentOffset.x)
{
// moved left
NSLog(@"scrolling left");
double currentPageOffset = floor((scrollView.contentSize.width -
scrollView.contentOffset.x) / itemWidth);
currentPage = totalPages - currentPageOffset;
nextPage = currentPage <= 0 ? 0 : currentPage - 1;
}
int xOffset = (nextPage * itemWidth);
int nextOffsetPage = (totalPages - ((scrollView.contentSize.width - xOffset) /
itemWidth)) + 1;
[scrollView scrollRectToVisible:CGRectMake(xOffset,
0,
collectionView.bounds.size.width,
collectionView.bounds.size.height)
animated:YES];
}
この方法をあきらめた後、scrollViewWillBeginDecelerating:
代わりにこの方法を使用してみましたが、まったく同じコードが完全に機能しますか?? 代わりにメソッドを使用しようとしているscrollViewWillEndDragging:
理由は、次の 2 つの理由からです。
- スクロールの速度に基づいてジャンプ先のアイテムを微調整したい
- 慣性なしで指を離してドラッグを停止した場合、
scrollViewWillBeginDecelerating:
メソッドは呼び出されません。
このコールバックが何をしているのか誤解していますか?