美文网首页
CAScrollLayer

CAScrollLayer

作者: 叶小馨 | 来源:发表于2017-04-16 15:04 被阅读50次

原文

If you’re going to be moving a layer’s bounds origin as a way of repositioning its sublayers en masse, you might like to make the layer a CAScrollLayer, a CALayer subclass that provides convenience methods for this sort of thing. (Despite the name, a CAScrollLayer provides no scrolling interface; the user can’t scroll it by dragging, for example.) By default, a CAScrollLayer’s masksToBounds property is YES; thus, the CAScrollLayer acts like a window through which you see can only what is within its bounds. (You can set its masksToBounds to NO, but this would be an odd thing to do, as it somewhat defeats the purpose.)
To move the CAScrollLayer’s bounds, you can talk either to it or to a sublayer (at any depth):
Talking to the CAScrollLayer
scrollToPoint:
Changes the CAScrollLayer’s bounds origin to that point.
scrollToRect:
Changes the CAScrollLayer’s bounds origin minimally so that the given portion of the bounds rect is visible.
Talking to a sublayer
scrollPoint:
Changes the CAScrollLayer’s bounds origin so that the given point of the sub‐ layer is at the top left of the CAScrollLayer.
scrollRectToVisible:
Changes the CAScrollLayer’s bounds origin so that the given rect of the sub‐ layer’s bounds is within the CAScrollLayer’s bounds area. You can also ask the sublayer for its visibleRect, the part of this sublayer now within the CAScroll‐ Layer’s bounds.

翻译

如果你要移动一个layer的bounds的origin作为重新定位它的子layer的途径,你要或许要设置该layer为CAScrollLayer,CALayer的子类提供了便利的方法处理这些事情。(尽管CAScrollLayer没有提供一个滑动的界面);用户不能滚动他通过拖拽。)默认情况下,一个CAScrollLayer的maskToBounds 属性是YES;所以CAScrollLayer的行为像一个窗口,你只能看到只是它里面的东西。(你可以设置maskToBounds 为NO,但是这将是一件奇怪的事情,因为他有点南辕北辙)。
去移动CAScrollLayer的bounds,你可以和他或者他的子layer对话(任何深度的子layer):

  • 和CAScrollLayer对话

    • scrollToPoint:改变CAScrollLayer的bounds的origin到这个点。
    • scrollToRect:
      最小限度的改变CAScrollLayer的bounds的origin,所以他分配了一个可见的rect。
  • 和子layer对话

    • scrollPoint:改变CAScrollLayer’s bounds origin,所以让子layer在他左上角的位置。
    • scrollRectToVisible:改变CAScrollLayer’s bounds origin,所以让子layer的bounds在CAScrollLayer’s bounds 的区域内部。你同样能和他子layer的visibleRect对话,这个子layer的部分在这个CAScrollLayer’s bounds内部。

相关文章

  • CAScrollLayer

    原文 If you’re going to be moving a layer’s bounds origin a...

  • Calayer

    示例 #1:CALayer 示例 #2:CAScrollLayer 示例 #3:CATextLayer 示例 #4...

  • CAScrollLayer(滚动图层)

    CAScrollLayer提供了和UIScrollView的基本功能。只不过它是layer,只负责显示,不响应用户...

  • CoreAnimation之CAScrollLayer

    CAScrollLayer和UIScrollView的显示功能是一样的,可以滚动显示比窗口更大的内容,只是CASc...

  • CALayer CAScrollLayer CATextLaye

    CALayer Layer的基本属性: Layers像Views有subviews一样,也有sublayers;当...

  • CALayer解析2:CAScrollLayer

    1.简介 CAScrollLayer是CALayer的子类,显示的是可滚动的图层的一部分,UIScrollView...

网友评论

      本文标题:CAScrollLayer

      本文链接:https://www.haomeiwen.com/subject/mgyaattx.html