CALayer 内的 UIScrollView
我正在开发某种纸牌游戏,其中我的视图对象(纸牌等)都是 CALayers。这些对象被添加为 mainBoard
(CALayer)的子层,而它又是我的 mainView< 的
[UIView layer]
属性的子层/代码>。一切都很好,我可以进行命中测试,以正常通过 mainView
类的 touchesBegan:withEvent:
回调来验证哪个层被触摸,等等。
但是,我需要在 mainBoard
内有一个滚动条来显示“更大”的 CALayer,因此我尝试首先在 CAScrollLayer
内添加“更大”的 CALayer,但我注意到CAScrollLayer
并不真正滚动(不处理用户输入,也不绘制滚动条)。因此,解决方法是将 UIScrollView 直接添加到 mainView
UIView。 UIScrollView
完美滚动,直到我尝试使用 [scrollView.layer addSublayer:
向其添加“更大”层。
有谁知道如何在 CALayer 中拥有“可滚动”对象吗?
谢谢!
I'm developing some kind of card game in which my view objects (cards, etc) are all CALayers. These objects are added as sublayers of a mainBoard
(a CALayer), which, in turn, is a sublayer of the [UIView layer]
property of my mainView
. Everything is Ok, I can do hit testing to verify which layer is being touched through the touchesBegan:withEvent:
callback of the mainView
class normally, and so on.
However, I need to have a scroll inside my mainBoard
to show "bigger" CALayers, so I tried first adding the "bigger" CALayer inside a CAScrollLayer
, but I noticed that the CAScrollLayer
doesn't really scroll (doesn't handle user input, neither draws scrollbars). So, the workaround would be to add an UIScrollView directly to the mainView
UIView. The UIScrollView
scrolls perfectly, until I try to add the "bigger" layer to it, by using [scrollView.layer addSublayer:<bigger layer>]
.
Does anyone has any idea of how I can have "scrollable" objects inside a CALayer?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nacho4d 指出了我的问题的答案。
回复标记:“更大”图层(边界大于屏幕中可用区域的图层(因此需要包含在可滚动区域中))。
解决方案是首先将“更大”层包装在 UIView 中:
之后,我可以将视图添加为 UIScrollview 的子视图:
问题是我试图直接将“更大”层添加为 UIScrollview 的子层相反,将其包装在 UIView 中并将其添加为子视图是有效的。
谢谢
nacho4d pointed the answer for my question.
Replying to mark: the "bigger" layer (a layer whose bounds is bigger than the area available in the screen (and so, needs to be contained in a scrollable area)).
The solution was to first wrap the "bigger" layer in a UIView:
afterwards, I can add the view as a subview of the UIScrollview:
The problem was that I was trying to add the "bigger" layer as a sublayer of the UIScrollview directly, instead, wrapping it in a UIView and adding it as a subview worked.
Thanks