Umeumeume
Umeumeume

Reputation: 1988

How to fire "scrollsToTop" after tapping the status bar programmatically?

I want to fire scrollsToTop function which fired when you tap the status bar programmatically if users tap the navigation bar title.

This is my method at the moment.

[tableView_ setContentOffset:CGPointMake(0, 0) animated:YES];
[tableView_ flashScrollIndicators];

But, it does not animate ScrollIndicators like you tap the status bar to scroll to the top.

Any help will be appreciated, thanks!

Upvotes: 0

Views: 854

Answers (3)

Friesgaard
Friesgaard

Reputation: 3204

Try something like

-(void)doScroll{
    void (^scroll)(void) = ^{
        [contentTableView setContentOffset:CGPointMake(0, 0) animated:NO];
        [contentTableView flashScrollIndicators];
    };

    [UIView animateWithDuration:0.5 animations:scroll];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self performSelector:@selector(doScroll) withObject:nil afterDelay:1];
}

Upvotes: 1

Naren
Naren

Reputation: 23

Try this in ShouldStartLoadWithRequest Delegate method of web view

    ((UIScrollView *)[[self.challengeWebView subviews] objectAtIndex:0]).scrollsToTop = NO;

Upvotes: 0

Kristofer Sommestad
Kristofer Sommestad

Reputation: 3061

Have you tried using -setContentOffset:animated in combination with the UIScrollViewDelegate methods - (void)scrollViewDidScrollToTop: and/or -(void)scrollViewDidEndScrollingAnimation:?

You might be able to send your -flashScrollIndicators in one of those instead of relying on timers, i.e. by using -performSelector:withObject:afterDelay).

Upvotes: 1

Related Questions