4

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?

4

2 回答 2

6

想法 1:您需要关闭分页,为反弹设置动画,然后重新打开分页。

想法2:你的第二步来得太早了:

scheduledTimerWithTimeInterval:0.01

尝试更长的时间间隔!我会从0.4.

想法3:为什么不使用反弹而不是使用flashScrollIndicators?这正是它的目的!

于 2013-04-27T17:18:56.143 回答
1

使用 NSTimer 时出现内存问题。这就是为什么我使用另一种解决方案进行滚动视图预览。

        [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){
                                              }
                              ];
                         }
         ];
于 2015-11-27T18:48:37.350 回答