How to use drawRect with a subclass of UIScrollView?
I'm trying to implement an owner-drawn view that is a subclass of UIScrollView
. Basically, I want to custom-draw the contents of the view, and then have the stuff I've drawn be scrollable.
I've overridden drawRect
in my view and I'm able to draw my contents, scaled to the size of the UIScrollView's contentSize property (so some of my custom drawing is not visible, as I intended).
The problem is that the content then never moves. I can drag my finger up and down, and this makes the UIScrollView's scrollbars appear, but my custom-drawn content never moves or开发者_Python百科 changes - I still always only see the top half.
How can I custom-draw content for this UIScrollView so that what I've drawn is scrollable?
Are you calling [super drawRect];
at the end of your own drawRect
method?
Edit
I misread the question. You'll need to create your own UIView
subclass and put your overridden drawRect
in that. Then, add that view as a child of the UIScrollView
.
精彩评论