How to detect scrolling direction of a tableview?

You must Login before you can answer or comment on any questions.

Hello,

I am trying to let the navbar slide up when scrolling a tableview down and have it slide down again when scrolling up. This is my code and it kind of works. Except for two things. Is there a better way of detecting what direction the table is scrolling?

  1. When I reach the bottom the navbar slides down.
  2. I get this warning: [WARN] New layout set while view [object TiUIView] animating: Will relayout after animation.
    EventMessages.addEventListener ('scroll',function(e) {
     
            if (offset < e.contentOffset.y && offset > 0) {
     
                navbar.animate({top: -70, duration:50}, function(){
     
                    offset = e.contentOffset.y;
     
                });
     
            } else {
     
                navbar.animate({top: 0, duration:50}, function(){
     
                    offset = e.contentOffset.y;
     
                });
     
            }
     
        });

2 Answers

to remove the warning, provide a delay using setTimeout so that the animations dont overlap.

to determine direction, can't you check to see if the offset is increasing or decreasing?

— answered 10 months ago by Aaron Saunders
answer permalink
2 Comments
  • Ok, will add delay. About the direction, I think I am checking if it increases or descreases. Could you check my code and perhaps refactor it? Thanks!

    — commented 10 months ago by Daniel Krusenstråhle

  • My code is not reliable to determine scrolling direction of the table. What I need to do is as soon as the user scrolls up the navbar must dissappear and as soon as they scroll down it must reappear. How can I do this?

    — commented 9 months ago by Daniel Krusenstråhle

well, i'm also trying to solve the problem. When i check the api document, i found Ti.UI.Window has a event swipe and this event has a property called direction which can tell your finger is swiping left/right/up/down. So i'm wondering maybe you can add your nvabar in the window, and listen to 'swipe' event of the window. i didn't try it, i'll do it later and keep you informed.

/kent

Your Answer

Think you can help? Login to answer this question!