首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置遮罩层锚点时需要帮助

设置遮罩层锚点时需要帮助
EN

Stack Overflow用户
提问于 2015-08-12 20:17:23
回答 1查看 614关注 0票数 0
代码语言:javascript
复制
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为绿色,无任何遮罩

带遮罩但无锚点的绿色vview

带有遮罩和锚点的绿色vview

EN

回答 1

Stack Overflow用户

发布于 2015-08-12 20:52:23

有关锚点的文档:

代码语言:javascript
复制
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

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

代码语言:javascript
复制
mask.anchorPoint = CGPointMake(0.5,0.5);

这是默认值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31964991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档