iOS基石 —— CALayer

来源:互联网 发布:playclub捏脸数据论坛 编辑:程序博客网 时间:2024/04/30 06:41
//CALayer 层(图层)//每个view(视图)都附着在一个层上 通过改变这个层 可以改变view的形状、边框、颜色等等UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];//设置锚点 即中心点cell.layer.anchorPoint = CGPointMake(0, 0);redView.backgroundColor = [UIColor redColor];//CALayer view的属性 修改view的圆角redView.layer.cornerRadius = 20;//设置边框宽度redView.layer.borderWidth = 8.f;//设置边框颜色 颜色的CGColorredView.layer.borderColor = [UIColor greenColor].CGColor;//剪切超出的部分redView.layer.masksToBounds = YES;

//设置圆头像

UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(100, 220, 100, 100)];imageV.image = [UIImage imageNamed:@"image1"];self.view.backgroundColor = [UIColor blueColor];imageV.layer.cornerRadius = 50; imageV.layer.masksToBounds = YES;[self.view addSubview:redView];[self.view addSubview:imageV];

//动画

//CAAnimation动画类  创建按一个动画CAAnimation *anima = [CAAnimation animation];//CAAnimation 的子类 CATransitionCATransition *tans = [CATransition animation];//选择动画的类型tans.type = @"fade";//动画的方向tans.subtype = @"fromRight";//动画的时间tans.duration = 2.0;//动画的次数tans.repeatCount = 2;//在layer层上添加动画//[redView.layer addAnimation:tans forKey:@"key1"];//移除layer层的动画//[redView.layer removeAnimationForKey:@"key1"];//三维动画CABasicAnimation *baAnima = [CABasicAnimation animationWithKeyPath:@"transform"];//第一个参数:角度   x x轴 y y轴 z z轴NSValue *value = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(3.14, 2, 1, 0)];baAnima.toValue = value;baAnima.duration = 2.0;baAnima.repeatCount = 60;//在layer层上添加动画[imageV.layer addAnimation:baAnima forKey:@"key2"];
原创粉丝点击