scroller iPhone with bounce

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

scroller iPhone with bounce

Post by bn » Wed Dec 08, 2010 1:30 am

I figured the scroller example in Livecode mobile 4.5.2 was not really complete so I set up the new scroller in a little stack: a list field with a bounce. The bounce was not obvious from the example so I hope this helps people to implement this. (look at the group "umscroll" with lockloc true and the list field)
Almost all the code is in the card script. Except for a mouseUp handler in the list field to make the actual selection.

The new scroller is a very nice object that really makes things a lot easier. It scrolls very smoothly even on my slow iPhone 3G. Selection is a lot easier since the operating system takes a lot of guesswork out of when a touch is the begin of a scroll and when a touch is a selection.

There is one quirk in the current incarnation of the mobile engine:
the scroll is really only starting to scroll if you slide the field up and then touch the network bar or whatever you call it. The top line of the screen where the battery is shown etc. This 'defrosts' the scrolling and from then on you can scroll and bounce like you expect it. Runrev is aware of the problem.

You will want to test this stack on a real device, the simulator does not let you scroll really.

Edit: 29th jan 11
removed the link to the stack and attached a current version instead, same stack as further down below, look there for comments on the stack.


Edit 8th Feb 11:
current version of this stack is attached to this message:
http://forums.runrev.com/phpBB2/viewtop ... =49&t=6876

lcMobileScroll_0.0.3.livecode.zip
(10.05 KiB) Downloaded 399 times


Kind regards

Bernd
Last edited by bn on Tue Feb 08, 2011 3:14 pm, edited 4 times in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: scroller iPhone with bounce

Post by bn » Mon Jan 10, 2011 7:51 pm

Just wanted to add that the above version of a scrolling list field is deprecated with the advent of the newer livcode mobile command for scrolling of groups unboundedHScroll and unboundedVScroll.

You might want to investigate that.

Kind regards
Bernd

jjeye101
Posts: 3
Joined: Thu Jan 27, 2011 4:34 pm

Re: scroller iPhone with bounce

Post by jjeye101 » Thu Jan 27, 2011 5:03 pm

Hi Bernd,
thanks for your little app...it helped a newbie like me to get to grips this platform.

Using your code as an example, i want to select a particular field from the scrolling field and navigate to another card.

Using your field "fldRolf" i have made the following changes to the code

Code: Select all

on mouseUp
   -- if not isBusy() then
   -- set the hilitedLine of field "fldRolf" to  (word 2 of the clickLine)
   -- put the hilitedText into field "Offsets"
   -- set the hilitedLine of field "fldRolf"  to (word 2 of the clickLine) -- displays the selected text in the message box
   --set the traversalOn of field"fldRolf" to false
   --put the selectedText of field "fldRolf"
   --if (the selectedText of field "fldRolf" is "	Abel Franziska") then
      switch (the selectedText of field "fldRolf")
  case "	Abel Franziska"
   go to  card "Abel Franziska" 
    break  
  --end if
   end switch
end mouseUp
i have created a new card called "Abel Franzika" and am succesfully able to navigate to this. I can also display the contents of the field in the Message Box. When i run this app now, it shows me the contents of the field or by selecting the case " Abel Franziska" i can also navigate to the card.

However, when i simulate this in IOS, nothing happens. however, there is no error message.

would you know why?

any help would be appreciated. 8)

kind rgds,
Jan

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: scroller iPhone with bounce

Post by bn » Thu Jan 27, 2011 9:16 pm

Hi Jan,
first of all, welcome to the forum.

Actually I am glad you asked since it showed a problem with the stack. A lot of people downloaded it and no one complained.

well there is an error message in the field at the bottom, it is just hard to read because the font is so small. Unfortunately the error message is not really helpful.


The reason for the stack not working is a bit embarassing for me and for Runrev:

For me because I did not test to go to another card.

For Runrev because I took the card script from the example stack they provided and at that time there was an error in the documentation. It listed iphoneControlDestroy instead of iphoneControlDelete
so you should replace in the card script of the first card the on closeCard handler with the one below. Than it works.

Code: Select all

on closeCard
   if the environment is not "mobile" then
      exit closeCard
   end if
   iphoneControlDelete sScrollerId
end closeCard
Be aware of what I said in the second post. The way the bouncing is handled is a bit obsolete. Now livecode for iOS supports an unboundedHScroll and unboundedVScroll for groups if you turn that property on.
This is easier to use than the work-around for bouncing I used in the above stack. I always intended to update a simple scrolling stack with a bounce, never got around to do it.

Kind regards
Bernd

jjeye101
Posts: 3
Joined: Thu Jan 27, 2011 4:34 pm

Re: scroller iPhone with bounce

Post by jjeye101 » Sat Jan 29, 2011 1:13 am

Hi Bernd,
Many thanks for the prompt reply...its nice to know that you are welcome to a forum :)

Many thanks to you for identifying the code issue. I'm sure that should resolve matters directly related to the app itself, however, I still cannot get the app to work on my computer. Again, this works as a LiveCode app, i can run this on my machine and it works, no problem. The only issue seems to be when I simulate this on iPhone Simulator, it ceases to work. Your unmodified app works just fine, tho.

Here's what I have done...since i cannot upload the stack itself :(

i. I have modified the Main card with the code that you suggested that I change.
ii. I have modified the field "FieldRolf" with this code

Code: Select all

on mouseUp
   -- if not isBusy() then
   --set the hilitedLine of field "fldRolf" to  (word 2 of the clickLine)
   --put the hilitedText into field "Offsets"
 put the selectedText into field "Offsets" 
 --put the selectedText into field "Offsets"
 if (the selectedText of field "fldRolf" = "	Abel Franziska") then
    go card "Abel Franziska"
 end if
end mouseUp
Now i can see what the contents of the line I select in the field (which appears in the Message Box) and I can also switch to the card that I have created called " Abel Franziska" (which somehow is the name appearing in the message box when i click on this - note the spaces in front of the name!).
It works fine, i have also created a button to navigate back to the main card. i can even simulate this use within the Offsets field with the other line of code that i have remarked out.

Apologize in advance for any shortcomings on my part, but i cannot make out what is wrong for the life of me :oops:

rgds,
jan

when i try to simulate this, i don't get anything. Nada. no error message either. i know what error message you are referring to, this is when i tried to

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: scroller iPhone with bounce

Post by bn » Sat Jan 29, 2011 10:42 pm

Hi Jan,

I did clean up the code and brought it to a working level with what we have today in iOS livecode.

I thought about posting a simplified version but decided against it. Some of the things would not be understood/working in a simplified version.
It still is just bare bones but I hope easily adaptable.

Some remarks
I use the HTML-Text of the list-field to set the text 3 pixel higher by using superscript. See the button fill field for the code. (that is the reason for the tab in front of the names, it is not spaces but a tab. Superscript only works if there is at least one character in front of the superscripted characters that is not superscripted. I chose a tab because you can adjust it with the tabstopps property of the field)

Some things, like a list of the names are in custom properties of the card.

I switch the listbehavior of the field off and on since I noticed it was too sensitive to accidental activation.

I now use the scroll of a group that comprises the list field instead of scrolling the list field. This makes the code easier

I set the bottom margin of the list field to make it bounce even if it has only a few items in it. By increasing the bottom margin to just one pixel greater the the scrolling rect bouncing is preserved.

I now made a second card and included a transition when going to that card. You can select any name and it goes to this one card.

If you have further questions please feel free to ask.


Kind regards

Bernd



Edit 8th Feb:

current version of this stack is attached to this message:
http://forums.runrev.com/phpBB2/viewtop ... =49&t=6876
Attachments
lcMobileScroll_0.0.3.livecode.zip
(10.05 KiB) Downloaded 366 times
Last edited by bn on Tue Feb 08, 2011 3:12 pm, edited 1 time in total.

ludo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 72
Joined: Mon Dec 03, 2007 6:10 pm

Re: scroller iPhone with bounce

Post by ludo » Sun Jan 30, 2011 9:29 pm

Thanks !

Great job.

But it seem there is a limit on the number of lines (or in the formattedheight) of a field (iOs limit ?) : i cannot scroll after 800 lines

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: scroller iPhone with bounce

Post by bn » Sun Jan 30, 2011 10:35 pm

Hi Ludo,

thanks.

I don't know where that limitation comes from, I never tried to put more than about 120 Names = Lines into the list field. Good to know. I know there is a limit to the width of what can be displayed in a line of a field, but I never heard of a limit on the length or formattedLength of a field.

Kind regards

Bernd

jjeye101
Posts: 3
Joined: Thu Jan 27, 2011 4:34 pm

Re: scroller iPhone with bounce

Post by jjeye101 » Mon Jan 31, 2011 2:29 pm

Thank you Bernd, this is very helpful. I am looking at your code - making sense of it, will ping you once I understand it well enough to put forward some sensible questions.

I am also looking to incorporate search functionality within the application as well, will update you on how that is going.

kind rgds,
jan

Post Reply