Bounce UIScrollView - hint that there's more

2019-04-10 04:20发布

I'm developing an app with a scroll view in it. It's not immediately obvious that there's more content, and there's no scroll indicator (scroll view is paged).

So, to give the user a 'hey, there's something down here...', I would like to have the scroll view do a subtle bounce - down then up - on launch. I've tried this:

- (void)viewDidLoad
    ....
    [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(bounceScrollView) userInfo:nil repeats:NO];
}
- (void)bounceScrollView
{
    [self.verticalScrollViews[0] scrollRectToVisible:CGRectMake(0, 600, 1, 1) animated:YES];
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(_unbounceScrollView) userInfo:nil repeats:NO];
}
- (void)_unbounceScrollView
{
    [self.verticalScrollViews[0] scrollRectToVisible:CGRectZero animated:YES];
}

However, this code makes the view get 'stuck' at about halfway between two pages.

Any help?

2条回答
【Aperson】
2楼-- · 2019-04-10 04:46

Idea 1: You need to turn off paging, animate the bounce, and turn the paging back on.

Idea 2: Your second move is coming way too soon:

scheduledTimerWithTimeInterval:0.01

Experiment with longer time intervals! I would start with 0.4.

Idea 3: Instead of your bounce, why not use flashScrollIndicators? This is exactly what it is for!

查看更多
干净又极端
3楼-- · 2019-04-10 04:53

I had a memory problems when using NSTimer. That's why I used another solution for scrollView preview.

        [UIView animateWithDuration:1.0
                              delay:0.00
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             _scrollView.contentOffset = CGPointMake(200,0);
                         }
                         completion:^(BOOL finished){
                             [UIView animateWithDuration:1.0
                                                   delay:0.00
                                                 options:UIViewAnimationOptionCurveEaseInOut
                                              animations:^{
                                                  _scrollView.contentOffset = CGPointMake(0,0);
                                              }
                                              completion:^(BOOL finished){
                                              }
                              ];
                         }
         ];
查看更多
登录 后发表回答