UIScrollView が常に特定のポイントにスクロールして戻るようにします。私は書くことによってそれを達成しました:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
(*targetContentOffset).x = 0.0f;
}
1つの例外を除いて、かなりうまく機能します。十分にスクロールしてビューの最後に到達し (バウンスが開始されます)、指を引き上げると、ビューはスムーズにスクロールし、少し減速して停止し、設定した場所にジャンプします (アニメーションなし)。スクロール ビューの最後までスクロールしない限り、発生しません。
UIScrollViewを初期化する方法は次のとおりです
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 284, frame.size.height)];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.delegate = self;
[scrollView setContentSize:CGSizeMake(285,frame.size.height)];
[self addSubview:scrollView];
UIEdgeInsets inset = scrollView.contentInset;
inset.left = 60;
inset.right = 60;
[scrollView setContentInset:inset];