需要帮助设置遮罩层锚点

时间:2015-08-12 12:17:23

标签: ios objective-c calayer mask

CALayer *mask = [CALayer layer];
mask.contents = (id)[[self getImg]CGImage];
mask.frame = CGRectMake(0, 0, self.vview.frame.size.width, 100);
mask.anchorPoint = CGPointMake(0.5, 1.0);
self.vview.layer.mask = mask;

我正在设置UIView vview上的模板,vview高度为300但是当我设置anchor point模板层跳起大约50px时,我该怎么办?要保持原来的位置。

vview in green without any masking 绿色vview没有任何掩蔽

vview in green with masking but no anchor point vview绿色与掩蔽,但没有锚点

vview in green with masking and anchor point vview绿色与掩蔽和锚点

1 个答案:

答案 0 :(得分:0)

关于锚点的文档:

anchorPoint
 Property
Defines the anchor point of the layer's bounds rectangle. Animatable.

Declaration
SWIFT
var anchorPoint: CGPoint
OBJECTIVE-C
@property CGPoint anchorPoint
Discussion
You specify the value for this property using the unit coordinate space. The default value of this property is (0.5, 0.5), which represents the center of the layer’s bounds rectangle. All geometric manipulations to the view occur about the specified point. For example, applying a rotation transform to a layer with the default anchor point causes the layer to rotate around its center. Changing the anchor point to a different location would cause the layer to rotate around that new point.

For more information about the relationship between the frame, bounds, anchorPoint and position properties, see Core Animation Programming Guide.

几何操作:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimationBasics/CoreAnimationBasics.html

基于此,如果您不想移动蒙版,只需将锚点设置为

即可
mask.anchorPoint = CGPointMake(0.5,0.5);

这是默认值。