scrollTo in scrollView doesn't work !?!?
Here is my code:
var scrollView = Titanium.UI.createScrollView({
contentHeight: 600,
top:0,
showVerticalScrollIndicator:true
});
scrollView.scrollTo(0, 100);
but nothing happens. Is it a bug?
2 Answers
-
I had an issue where I wanted the view to scroll when the window loads, but there is no
onload
event for windows. So I did a setInterval:var offset = 0; scrollView.addEventListener('scroll', function(e) { if (e.y!=null) { offset = e.y; Ti.API.info('offset: '+offset); } else { Ti.API.info('offset: null.. no idea why'); } }); var init = setInterval(function(e){ Ti.API.info('check if '+offset+' = 50'); if (offset==50) { Ti.API.info('we are done'); clearInterval(init); } scrollView.scrollTo(0,50); },100);
See my answer here.
-
A ScrollView has to contain another view which is larger than the ScrollView itself. When this happens, the ScrollView can be made to move the view(s) it contains around. In your example, you have a ScrollView and nothing else so there is nothing to scroll. If you look at the Kitchen Sink scroll_view_basics.js you'll see some good examples of how a ScrollView is used. And no, there is no bug I am aware of at this time.
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.ScrollView-object