如何将drawRect与UIScrollView的子类一起使用?
我正在尝试实现一个所有者绘制的视图,它是 UIScrollView
的子类。基本上,我想自定义绘制视图的内容,然后让我绘制的内容可以滚动。
我已经在视图中重写了 drawRect
,并且能够绘制我的内容,并缩放到 UIScrollView 的 contentSize 属性的大小(因此我的一些自定义绘图不可见,正如我所希望的那样)。
问题是内容永远不会移动。我可以上下拖动手指,这会使 UIScrollView 的滚动条出现,但我的自定义绘制内容永远不会移动或更改 - 我仍然总是只能看到上半部分。
如何为此 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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在自己的
drawRect
方法末尾调用[super drawRect];
?编辑
我读错了问题。您需要创建自己的
UIView
子类,并将重写的drawRect
放入其中。然后,将该视图添加为UIScrollView
的子视图。Are you calling
[super drawRect];
at the end of your owndrawRect
method?Edit
I misread the question. You'll need to create your own
UIView
subclass and put your overriddendrawRect
in that. Then, add that view as a child of theUIScrollView
.