CAScrollLayer

原文

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)