Disable scrolling on scrollview by touch
Hi all,
I had a problem where I was using a scrollableview and didn't want the user to be able to scroll it by touching it but wanted them to use some next/back buttons.
If I disabled the touch then none of the controls on the view would work!
I found a solution by enhancing the SDK with a new "scrollEnabled" property in much the same way as touchEnabled. Note this is iOS only.
This is actually supported in iOS with a UIScrollView's "scrollEnabled" property.
Modify the SDK file TiUIScrollableView.m
add this
/* CSM: Provide ability to disable scrollviews scrolling when touched */
-(void)setScrollEnabled_:(id)args
{
scrollingEnabled = [TiUtils boolValue:args];
[scrollview setScrollEnabled:scrollingEnabled];
}
Down anywhere (I have it just after this)
-(void)setViews_:(id)args
{
if ((scrollview!=nil) && ([scrollview subviews]>0))
{
[self refreshScrollView:[self bounds] readd:YES];
}
}
Now you should also add the scrollingEnabled into your TiUIScrollableView.h. I put it at the bottom of the object definition.
int cacheSize;
BOOL scrollingEnabled;
Note. You don't need that variable, I just thought it'd be nice to store it.. note I haven't done a gettor…
Then in you JS code you just do
yourscrollableview.scrollingEnabled = true/false
And it now means you can programatically control the scrollable view without people moving them and yet controls on the views (in your array attached to the scrollable view if doing multiple) still respond.
Enjoy.
4 Answers
-
If anyone is still looking for help with this issue here, you should take note that as of Titanium SDK 2.0, you can use the property "scrollingEnabled: false" to disable user scrolling via swipe. You can then use on screen controls to programmatically scroll to the desired view.
Just to be clear, the property is scrollingEnabled, NOT scrollEnabled.
-
Add the scrollableView to a parentView. Disable touchEnabled property of scrollableView.
Add the buttons to parentView (NOT to scrollableView), with an higher zIndex.
Capture clicks from buttons and slide the scrollableView whatever you want, using method scrollToView
-
Hi Chris,
I'm having trouble getting this to work. I'm using the latest 1.8 build but it just does not appear to want to work and I'm unable to reference it. (Obviously, I've tried clean builds and it appears within the classes the build is using)
-
Hi Chris,
I have tried this SDK hack several times, but can't get it to work. I am using the latest build also. Your help is greatly appreciated.