换句话说,当:
scrollView.pagingEnabled = YES;
scrollView.bounces = YES;
一切正常,除了我不喜欢第(0)页和第(1)页的反弹。但当我这么做的时候:
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
它停止在每个页面上捕捉到位,而是将所有页面视为一个长页面。因此,似乎出于某种原因,分页依赖于反弹,只要我能够以某种方式停止反弹,这是很好的。那么,有没有别的办法摆脱它呢?还是我做错了什么?
编辑:
@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];
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;
if (offset.x != contentOffset.x || offset.y != contentOffset.y)
{
[super setContentOffset:offset];
}
}
@end