Implementing ScrollView from Jason's iOSKit

Hi

Does anyone know if the ScrollView extension from iOSKit is usable and if there is an example of its use available?

Thanks

Chris

Hi Chris, there are some problems with it that I haven’t had the time to fix yet so you won’t be able to make it work properly. In the time up until I fix it (could be several weeks) you can try to use the one in iOSLib. I forgot to update the Readme to remove it from the list, and that’s also the reason there is no example view of its use.

Thanks very much Jason for the reply and iOSKit. I wasn’t aware of the existence of iOSLib, but I’ll sus it out straight away.

Cheers

Jean-Paul, thank you too for replying. is dtPlugins for iOS?

… and I’m sure you found iOSLib in the meantime and the ScrollView demo in the Graphics demo project. The documentation Wiki is not fully up to date. If you’d have any questions, feel free to ask.

I did Ulrich, but I ran into a snag with the download so I wasn’t able to see ScrollView - I copied the iOSLib folder as instructed into the project, but got tones of errors building (item does’t exist, etc), so I left it. It would be great if you could give me a pointer on what I might be doing wrong.

Thanks

Chris, you probably are just the victim of a strange error. When you copy the iOSLib folder to the demo project, some classes could be renamed, getting a number or the “xoxo_code” as an extension of their name. I don’t know the reason and cannot reconstruct it here – when I download the zip, everything runs nicely. I’ll send you a PM with the download link to a running project which you can use as template for the library.

Instead of a PM (in case others experience this issue too):
https://www.dropbox.com/sh/qm946zkjukgphon/AADSfiw4c0Y1Db2ztsLIGTZia?dl=0

Thanks Ulrich - that worked, though I think we got our wires crossed along the way - What I meant by scroll view was to be able to scroll controls off and onto a view. Your scroll is cool though - Is it ok to use for commercial use as is or do you have a license fee?

Thanks again

Great to read, Chris! I do have a license but no fee – it’s a “pay what you like if you like”-license. See below (from the Wiki).
For scrolling controls on and off the view: You did see the multi-view that’s built of the different iOSViews in the ScrollView demo?
Or is it about appearance and disappearance of controls?


Copyright & License

Written 2015 by Ulrich Bogun, xojoblog.me. This is a private project not connected to my job as german Xojo evangelist. This all is only possible because of the tremendous help of some extraordinary gurus sharing their wisdom on forum.xojo.com and, of course, the guys behind MacOSLib – without looking into it iOS declares would still be foreign to me. Therefore a copyright would be very stange and wrong. Again: iOSLib is free to use.

However, you surely can imagine this took me (and will probably take) a lot of time, and I want to continue refining the classes and adding more to them. If you use the classes and find them useful, feel absolutely free to send me a “keep it up”-contribution via PayPal to bogun (insert at sign) satzservice.de. The amount is completely up to you and every sum will be appreciated regardless of its height. If you cannot afford a few bucks or don’t want to: Hey, that’s still ok! Maybe you like to send me a line about their use or add a “Uses iOSLib …” line to your splashscreen. And if not, you’re still not a bad guy. Enjoy, share, contribute.

What I’m looking for is not to be limited by the screen size when in a view, much like Contacts, where you can swipe up and down on a contact to view or edit a large number of fields.

I think you might be taking about what happens after you press “Attach view” in AppleScrollViewer? - For me, nothing happens :-(Do I need to run in Xojo Beta?

I will definitely make a contribution, if I end up using iOSLib :slight_smile:

Instead of views with many controls that can scroll up and down, I think Apple’s Contacts app, and other similar apps, make extensive use of tables. My app happens to include contacts and I have used the dtPlugins ListView control - which you can think of as “an iOSTable on steroids” - to make a very close approximation.

Oh! I just realize I never updated the help text and give no hint about what “Attach view” does. When you tap on it, the three views of the project are added as subviews to the scrollview and the latter’s parameters are set to enable paged scrolling, meaning you have a vertically scrollable UI.

I’m dynamically adding controls to a scroll view (AppleScrollViewer from iOSLib), but I have a problem.

  1. If I add positioning constraints, and then add the control, it work fine in the iOS simulator, but crashes on the actual device.

  2. According to Norman Palardy, I should first add the control, and then the constraint. If I do this, the scrollview doesn’t scroll anymore.

Any ideas?

Hi Jan,

do you get any crash log for number 1?
I am not sure if I got you right. Do you add controls with attached constraints to the ScrollViewer? Are you sure this should work at all? Adding a control to a ScrollView means it becomes part of the scrollview’s layer hierarchy, so the parent is responsible for the placement of its child. I would rather catch a device orientation change at the scrollview and manipulate its children from this event.
Or does it crash when you add constraints to the scrollview?

Hi Ulrich

No, there are no crash logs.

Yes, I add controls to the ScrollViewer in it’s Open event. The app will only be used i Portrait-orientation, but the amount of controls exceeds the available space in one view. It’s OK that the controls becomes part of the scrollview’s layer hierarchy.

Here’s a simple example that illustrates what I try to do, and what’ happening: https://www.dropbox.com/s/hwy1cliqb41jtcg/ScrollViewTest.xojo_binary_project?dl=0

Thanks, Jan, will look into it soon.
What do you mean by the amount of controls exceeding the space in one view? You should be able to set the ScrollView’s contentsize property and can manipulate the position of an added control by setting its frame (or x, y) properties after addition.

EDIT:
Had a look into your project and am still not fully sure. You add constraints to the scrollview trying to hold a certain distance to the label you add. I don’t think that works. Are you trying to set the label’s position inside the scrollview with it? If that is so, simply forget about the constraints and set the label’s position after adding, like mylabel.AppleView.top = 150.

Hi Ulrich

That is what I’m doing:

  1. Setting content size of the scrollview

  2. Create a control with: Dim myLabel As New iOSLabel

  3. Add controls to the scrollview with: AppleScrollViewer1.AddControl(myLabel)

  4. Set the position of the control inside the scrollview with:
    Dim cTop As New iOSLayoutConstraint(myLabel, _
    iOSLayoutConstraint.AttributeTypes.Top, _
    iOSLayoutConstraint.RelationTypes.Equal, _
    AppleScrollViewer1, _
    iOSLayoutConstraint.AttributeTypes.Top, _
    1, _

AppleScrollViewer1.AddConstraint(cTop)

I think I start to remember dimly that when I built AppleScrollViewer, I had the feeling I made a fundamental mistake because it didn’t want to scroll at all. The reason was I was trying to add IDE-created controls to it which were attributed with constraints. It started to work once I removed the constraints. On a scrollview’s content they simply lock it up.

Have you tried replacing step 4 by a simple placement of myLabel as written in my last addition? And use no constraints at all? I think that should fix it.

Besides, are you assigning the constraints to the parent instead of the child? Not that it should work then, but it looks like the scrollview should keep a certain distance to its myLabel child when you would on a normal layout assign the constraint to the label, not its iOSView?

Yes, that’s the problem. When creating and adding controls with constraints to a scrollview’s content, they lock it up.

To set the position and size with Top, Left, Height and Width would be a simple replacement for constraints, but as far as I understand they are read-only properties.

I think I’m assigning the constraint to the label, and then relating it to the scrollview? Or am I doing this wrong? I have found noe other ways to do it.

You’re right, on the control alone the properties are read-only. But you can address the AppleView object of each iOSControl, and on this level you can either change the shadowed properties or pass a rect to the frame property. See my example above:

myLabel.AppleView.Top = 150