iOS Scrolling - need a cookbook

J. Landman Gay jacque at hyperactivesw.com
Sat Dec 8 00:02:55 EST 2012


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
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list