0

How do I build a freely scrollable view on iOS 5? I mean, I need to build a view which can scroll from left-right and top-down (any direction) and it will stay there. Inside this view, I need to place different kinds of objects.

(Imagine scrolling like a map. - I am using Storyboard.)

ikevin8me
  • 4,253
  • 5
  • 44
  • 84
  • What's the difference between a UIScrollView and what you want? – Phillip Mills May 17 '12 at 14:11
  • I tried using a UIScrollView, but the objects placed at the top always stay at the top. I played with the "bounces", etc. settings and that was what happened - it always stay on top (the positions of the top objects are fixed.) I need it scroll freely like a map. – ikevin8me May 17 '12 at 14:21
  • I've just seen your comment check my edit, under. – Martin May 17 '12 at 14:41

1 Answers1

4

Yeah, UIScrollView.

And don't forget to set the content size !! (every noobs - including me - are always asking the same question, why my scrollView does not work?)

=> [scrollView setContentSize:CGSizeMake(1000, 2000)], for example.

EDIT :

I just saw your comment. I don't understand what you call "on top".

I made an app with custom maps, and I used an UIScrollView to make the job: it was pretty good at it.

You just have to add each scrollable element as subviews of your UIScrollView. And set the contentSize to fit to the subviews' frames, of course.

Martin
  • 11,881
  • 6
  • 64
  • 110
  • I mean objects placed at the top-left are always staying at the top-left - even after I scrolled it and it bounces back to the top-left position. – ikevin8me May 17 '12 at 15:01
  • I'm going to try setting the size and see what happens. – ikevin8me May 17 '12 at 15:01
  • do you want infinite scroll ? If so what do you display after your last element ? If so again, you should set the contentSize dynamically – Martin May 17 '12 at 15:19
  • OK. I changed the UIView into UIScrollView and set the content size, and it worked! Thanks! – ikevin8me May 17 '12 at 15:19