Bounce UIScrollView - hint that there's more

こ雲淡風輕ζ 提交于 2019-12-21 19:44:17

问题


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?


回答1:


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!




回答2:


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){
                                              }
                              ];
                         }
         ];


来源:https://stackoverflow.com/questions/16254860/bounce-uiscrollview-hint-that-theres-more

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!