开发者

How to use drawRect with a subclass of UIScrollView?

开发者 https://www.devze.com 2023-02-20 09:08 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消