iOS Scrolling - need a cookbook

Graham Samuel livfoss at mac.com
Sat Dec 8 04:55:29 EST 2012


Jacque, what a treasure you are! What I hope to do now (there are some other pressures) is to experiment, refine this explanation a bit and write it up with a couple of diagrams (which sadly can't go into this list). I think it's pretty bad news that (AFAIK) very little of this has reached any of the official LC documentation - which means for example if one follows the sample stack it's very difficult to modify it without stopping it working. Scrolling is a very fundamental idea in mobile interfaces, and the method which LC have chosen to implement it are not obvious, nor are the consequences of setting the various parameters.

Thanks again

Graham

PS Yes I do have a scrollerDidScroll handler, but again I didn't find the way it worked particularly intuitive.

On 8 Dec 2012, at 06:02, J. Landman Gay wrote:

> On 12/7/12 12:17 PM, Graham Samuel wrote:
> 
>> Fumbling around, I have made scrollers work in the past, but I
>> realise that I don't know what I'm doing, so success has come by
>> luck, mostly. What I need is a nice clear "how to" description of
>> dealing with iOS scrolling. It may well exist, but so far i haven't
>> found it. Can anyone point me in the right direction?
> 
> There's an example stack in the resouces that ship with LiveCode. Under the Help menu choose Example Stacks and Resources which opens a Finder window. Then look for the Scroller Example stack.
> 
> Most everything is in there, though there's not a lot of explanation. I was confused about contentRect until I was told that the rect is relative to the scoller control. That is, the 0,0 topleft is always the topleft of the group or field you are scrolling; it isn't a card location. So if you want the entire content of the group or field to scroll, the scroller's contentRect will always start with 0,0 and the last two items will be the formattedWidth and formattedHeight of the group/field.
> 
> Basic concepts are:
> Ensure that the layermode for the group is "dynamic" and acceleratedRendering is on
> 
> Set the scroll(s) of the underlying group or field to 0
> Create the scroller
> Set the rect of the scroller to the visible area you want to display
> Set the contentRect of the scroller to the total area that should scroll (as per above)
> Set the scroll of the scroller to 0 -- may not be necessary but I do it
> Set any other properties you want (bounce, colors, paging, etc. Here's where you'd disable vertical scrolling if you don't want it)
> Set the visible of the scroller to TRUE -- for some reason the default is false, which means the scroller won't respond
> 
> If you need to restore a previous scroll position, set the scroll(s) of both the group and the scroller to a previously saved scroll amount as a last step.
> 
> I've found it best to delete the scroller when changing cards, and re-create it when opening the card.
> 
> You probably already have a scrollerDidScroll handler. It passes the x,y position of the scroller and you just set the scroll of the group to the same thing. If you don't want vertical scrolling, just ignore the Y parameter and only change the horizontal position of the group.
> 
> -- 
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com





More information about the use-livecode mailing list