首先,我不知道如何搜索这个,这就是为什么我将它作为一个问题发布。对不起,如果它已经被问到了,我还没有找到它。
我想让 scrollView 看起来像 App Drawer,所以它有 3 个可能的偏移量(如屏幕)。
这是我尝试过的代码,但这仅在我拖动并且不拿起手指直到滚动结束时才有效,但如果我滑动则不会结束:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (scrollView.contentOffset.x >= 0 && scrollView.contentOffset.x <= 640)
{
if (oldOffset == 0)
{
if (scrollView.contentOffset.x > 100 && scrollView.contentOffset.x < 420)
{
[scrollView setContentOffset:CGPointMake(320, 0) animated:NO];
oldOffset = 320;
}
else if (scrollView.contentOffset.x > 420)
{
[scrollView setContentOffset:CGPointMake(640, 0) animated:NO];
oldOffset = 640;
}
else
{
[scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
}
}
else if (oldOffset == 320)
{
if (scrollView.contentOffset.x < 220)
{
[scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
oldOffset = 0;
}
else if (scrollView.contentOffset.x > 420)
{
[scrollView setContentOffset:CGPointMake(640, 0) animated:NO];
oldOffset = 640;
}
else
{
[scrollView setContentOffset:CGPointMake(320, 0) animated:NO];
}
}
else {
if (scrollView.contentOffset.x < 220) {
[scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
oldOffset = 0;
}
else if (scrollView.contentOffset.x < 540) {
[scrollView setContentOffset:CGPointMake(320, 0) animated:NO];
oldOffset = 320;
}
else
{
[scrollView setContentOffset:CGPointMake(640, 0) animated:NO];
}
}
}
}