5

十分にドラッグしない場合は、UIScrollView のコンテンツ オフセットを元に戻したい:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(CGPoint *)targetContentOffset {
    self.endingOffset = scrollView.contentOffset;

    if(abs(verticalOffset) > [self cellHeight] / 9) { // If the user scrolled enough distance, attempt to scroll to the next cell
        ...
    } else if(self.nextCellOrigin.y != 0) { // The scroll view is still scrolling and the user didn't drag enough
        ...
    } else { // If the user didn't drag enough
        self.tableView.decelerationRate = UIScrollViewDecelerationRateNormal;
        (*targetContentOffset) = self.startingOffset;
    }
}

元の位置に戻すコードはelse部分にあり、常に機能します。ただし、十分にスクロールせずにジェスチャをすばやく行うと、元に戻ります。少しスクロールして、その位置を通常より少し長く保持すると、スムーズに元に戻ります。

ユーザーが UIScrollView に触れた時間について、API リファレンスには何も見つかりませんでした。たとえ触れたとしても、それを使用して元に戻すコードの動作を変更する方法がすぐにはわかりません。また、 setContentOffset:animated: を使用してその位置までスクロールしようとしましたが、ジャーキネスは修正されていないようです。

何か案は?

4

1 に答える 1

5

ジャーキネスが発生したときの速度を調べるために、速度を記録してみましたか?

編集

あなたができることは、willEndDragging メソッドの代わりに、これら 2 つの scrollView デリゲート メソッドを実装することです。このソリューションは、scrollView に別の感覚を与えますが、試してみてください。

checkOffsetメソッドに必要なすべてのロジックを入力します。

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

    // if scrollView's contentOffset reached its final position during scroll, it will not decelerate, so you need a check here too
    if (!decelerate) {
       [self checkOffset];
    }
}    

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
   [self checkOffset];
}


- (void)checkOffset {
    CGPoint newOffset;
    ...
    // Do all the logic you need to move the content offset, then:
    ...
    [self.scrollView setContentOffset:newOffset animated:YES];
}

編集#2: これも私のソリューションに追加すると、より良い結果が得られるかもしれません..試してみてください;)

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(CGPoint *)targetContentOffset {
    // This should force the scrollView to stop its inertial deceleration, by forcing it to stop at the current content offset
    *targetContentOffset = scrollView.contentOffset;
}
于 2013-04-03T23:44:43.260 に答える