ios - 在 mask 层之上询问 CATextLayer

标签 ios core-animation calayer

在我的应用程序中,我向 UIImageView 添加了一个 mask ,并将其设置为半不透明。此外,还有一个在该 CALayer 上运行的 CAAnimation。

现在,我想在上面添加一个 CATextLayer,它不能受到 mask 层的影响。我该怎么做?

谢谢

编辑:出现了一个新问题。不知何故,如果在 animationDidStart 中向 CATextLayer 发送消息,则动画将以相反的顺序执行。

- (void)viewDidLayoutSubviews {

for (int i=1; i<6; i++) {
    NSString* intValue = [NSString stringWithFormat:@"%d", i];

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];

    animation.duration = 0.5;

    animation.delegate = self;

    animation.repeatCount = 0;

    animation.autoreverses = NO;

    [animation setValue:intValue forKey:@"animationString"];

    animation.timingFunction = nil;

    [animation setRemovedOnCompletion:NO];

    [animation setFillMode:kCAFillModeForwards];

    animation.fromValue = (id) [self getCGRectForZoomLevel:i];

    animation.toValue = (id) [self getCGRectForZoomLevel:i + 1 ];

    animation.beginTime = CACurrentMediaTime() + i * 2;

    [self.shapeLayer addAnimation:animation forKey:intwaarde];


}

最佳答案

您应该重新考虑您的层次结构。

添加一个 View 作为容器,将 ImageView 和文本层分组,使它们成为兄弟(与现在文本层是 ImageView 的子层相比)

然后像您已经在做的那样屏蔽 ImageView 。

Container   // ⬅ this one is new
   ┃
   ┣━━ Image view ┅ (mask)
   ┃
   ┗━━ Text layer // ⬅ is now a sibling

关于ios - 在 mask 层之上询问 CATextLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16660444/

相关文章:

ios - 从当前 CAAnimation 的状态开始新的 CAAnimation

ios - 什么时候在 Swift 中为 View /图层设置边界和框架?

ios - 从 ViewController 导航回 SWRevealViewController 首页

android - 在 iOS 中定义 UITableView Cell 模板的简单方法类似于在 Android 中使用 MvxListView 完成的方式

iphone - 如何在 Xcode 3.2.5 中为企业内部分发准备应用程序?

ios - 为 UILabel 增加触摸手势区域

core-animation - NSWindow 增长动画(如快速查看窗口)

iphone - 核心动画还是 OpenGL ES?

iphone - 同步 UIView 动画

objective-c - CALayer是否保留CGColor对象?