ページングを含むUIScrollViewがあり(UIPageControlを使用し、ページ間を左右にドラッグ/フリックする一般的なモデル)、正常に機能しています。奇妙なことに、バウンスを取り除きたいと思ったときに(左側と右側のUIの後ろに黒が見えないように)、突然ページングが機能しなくなりました。
言い換えれば、いつ:
scrollView.pagingEnabled = YES;
scrollView.bounces = YES;
page(0)とpage(length-1)でのバウンスが気に入らないことを除いて、すべて正常に動作します。しかし、私がこれを行うとき:
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
各ページの所定の位置にスナップするのをやめ、代わりにすべてのページを1つの長いページとして扱います。したがって、何らかの理由でページングはバウンスに依存しているようです。バウンスをなんとか停止できる限り、これは問題ありません。それで、それを取り除く別の方法はありますか?それとも私が間違っていることがありますか?
編集: 解決策:
@interface PagingScrollView : UIScrollView
@end
@implementation PagingScrollView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
self.pagingEnabled = YES;
self.bounces = YES;
}
return self;
}
- (void)setContentOffset:(CGPoint)offset
{
CGRect frame = [self frame];
CGSize contentSize = [self contentSize];
CGPoint contentOffset = [self contentOffset];
// Clamp the offset.
if (offset.x <= 0)
offset.x = 0;
else if (offset.x > contentSize.width - frame.size.width)
offset.x = contentSize.width - frame.size.width;
if (offset.y <= 0)
offset.y = 0;
else if (offset.y > contentSize.height - frame.size.height)
offset.y = contentSize.height - frame.size.height;
// Update only if necessary
if (offset.x != contentOffset.x || offset.y != contentOffset.y)
{
[super setContentOffset:offset];
}
}
@end