Travis Griggs
Travis Griggs

Reputation: 22252

How to implement custom UIView which is scrollable/zoomable?

I want to create a "timeline" view. I'm comfortable with the GraphicsContext drawing API and using it in the drawRect: method. What I'm unclear of is the right/idiomatic way to make this view be scrollable/zoomable.

Is it more common to a) subclass UIScrollView or b) embed my custom view in stock UIScrollView placed inside storyboard?

Depending on which I use, how do I communicate my "desired bounds" to the scrolling machinery? And how do I make my drawing code aware of what the current scale/scroll is so I can draw appropriately.

(I did google for this, and haven't found any recent and simple recipes for this)

Upvotes: 2

Views: 364

Answers (1)

Nick Wilkerson
Nick Wilkerson

Reputation: 385

Don't subclass or embed. Set a UIScrollView as the outlet of your viewcontroller. UIScrollView inherits from UIView so you can treat it just like the normal UIView outlet of your view controller, plus you can scroll it.

Upvotes: 1

Related Questions