您的位置:首页 > 其它

隐式动画

2015-09-01 18:20 357 查看
1.每个UIView内部都默认关联着一个CALayer,称这个layer味Root Layer(根层)

2.所有的非Root Layer,也就是手动创建的CALayer对象,都存在着隐式动画

3.当对非Root Layer的部分属性进行修改时,默认会自动产生一些动画效果,而这些属性称之为Animatable Properties(可动画属性)

4.可动画属性:

bounds:用于设置CALayer的宽度和高度。修改该属性会产生缩放动画

backgroundColor:用于设置CALayer的背景色,修改该属性会产生背景色渐变的效果

@property (nonatomic, weak) CALayer *layer;

CALayer *layer = [CALayer layer];

// 设置尺寸

layer.bounds = CGRectMake(0, 0, 100, 100);

// 颜色

layer.backgroundColor = [UIColor redColor].CGColor;

[self.view.layer addSublayer:layer];

_layer = layer;

(void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event

{ // 获取触摸点

UITouch *touch = [touches anyObject];

CGPoint pos = [touch locationInView:self.view];

// 开启事务

// [CATransaction begin];

// 取消隐世动画

// [CATransaction setDisableActions:YES];

// _layer.position = CGPointMake(100, 100);

// 设置边框

_layer.borderWidth = arc4random_uniform(5) + 1;

CGFloat r = arc4random_uniform(256) / 255.0;

CGFloat g = arc4random_uniform(256) / 255.0;

CGFloat b = arc4random_uniform(256) / 255.0;

// _layer.borderColor = [UIColor colorWithRed:r green:g blue:b alpha:1].CGColor;

// 设置背景颜色

_layer.backgroundColor = [UIColor colorWithRed:r green:g blue:b alpha:1].CGColor;

// 设置圆角半径

_layer.cornerRadius = arc4random_uniform(50);

// 设置位置

_layer.position = pos;

// 提交事务

// [CATransaction commit];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: