OGeek|极客世界-中国程序员成长平台

标题: ios - 隐式动画淡入不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:29
标题: ios - 隐式动画淡入不起作用

我有一个 UIView 子类,它试图在它的一个 subview 之上创建一个圆角矩形覆盖。

当我使用下面的代码时,肯定会在我想要的地方出现一个绿色的圆角矩形,但无论我做什么,我都无法让它淡入。

CALayer *parentLayer = [self layer];

// Create a new layer and configure it to be a rounded rect box overlay
CALayer *layer = [CALayer layer];
layer.position = [slider layer].position;
layer.bounds = CGRectMake(0.0, 0.0, kWTFSliderWidth, kWTFSliderHeight);
layer.backgroundColor = [UIColor clearColor].CGColor;
layer.cornerRadius = 5.0;
layer.borderColor = [UIColor greenColor].CGColor;
layer.borderWidth = 3.0;

// Add the layer with a fade in to the parent layer
[parentLayer addSublayer:layer];

我必须手动将 CABasicAnimation 添加到我的父图层对象吗?默认实例不应该已经存在于 parentLayeraction 字典中吗?



Best Answer-推荐答案


将您的 addSublayer: 调用替换为:

layer.hidden = YES;
[parentLayer addSublayer:layer];
[CATransaction flush];
layer.hidden = NO;

关于ios - 隐式动画淡入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8661355/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4