标签:
- (void)viewDidLoad
{
[super viewDidLoad];
// 如果一个控制是另外一个控件的子控件, 那么这个控件中的layer也是另外一个控件的子layer
// NSLog(@"star - %@", self.view.layer.sublayers);
CALayer *layer = [CALayer layer];
layer.backgroundColor = [UIColor redColor].CGColor;
layer.bounds = CGRectMake(0, 0, 100, 100);
// layer.position = CGPointMake(200, 200);
// layer.contents = (id)[UIImage imageNamed:@"me"].CGImage;
[self.view.layer addSublayer:layer];
}
- (void)test
{
NSLog(@"star - %@", self.view.layer.sublayers);
// 1.创建layer
// CALayer *layer = [[CALayer alloc] init];
CALayer *layer = [CALayer layer];
layer.backgroundColor = [UIColor redColor].CGColor;
layer.bounds = CGRectMake(0, 0, 100, 100);
layer.position = CGPointMake(200, 200);
layer.borderWidth = 10;
layer.cornerRadius = 10;
// 将layer添加在界面上
[self.view.layer addSublayer:layer];
// NSLog(@"%@", layer.superlayer); // 获取layer的父视图
NSLog(@"end - %@", self.view.layer.sublayers);
//
// UIView *view = [[UIView alloc] init];
// view.superview;
// view.subviews;
// [self.view addSubview:view];
}
- (void)viewDidLoad {
[super viewDidLoad];
// 设置layer边框
self.imageView.layer.borderWidth = 10;
// 设置边框的颜色
self.imageView.layer.borderColor = [UIColor redColor].CGColor;//注意borderColor的类型
// 设置layer的圆角(设置主图层的圆角)
self.imageView.layer.cornerRadius = 10;
// 设置超出主图层的部分进行剪切操作
// self.imageView.layer.masksToBounds = YES;
// self.imageView.clipsToBounds = YES;
// 设置的image不是展示在主图层上的,是展示在子图层上的
self.imageView.layer.contents = (id)[UIImage imageNamed:@"LoginScreen"].CGImage;
// 设置阴影的颜色
self.imageView.layer.shadowColor = [UIColor blackColor].CGColor;
// 设置阴影的偏移位
// 如果是正数,代表向右移动
// 上
self.imageView.layer.shadowOffset = CGSizeMake(10, 10);
// 设置阴影的透明度0~1 1 完全不透明 0 完全透明
self.imageView.layer.shadowOpacity =1;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// self.imageView.transform = CGAffineTransformMakeTranslation(0, 100);
// self.imageView.layer.transform = CATransform3DMakeTranslation(0, 100, 0);
// NSValue *v = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, -200, 0)];
// [self.imageView.layer setValue:v forKey:@"transform"];
// [self.imageView.layer setValue:@(100) forKey:@"transform.translation.x"];
// self.imageView.transform = CGAffineTransformMakeRotationxx(M_PI_4);
// self.imageView.layer.transform = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);
[self.imageView.layer setValue:@"100" forKey:@"transform.translation.x"];
}
标签:
原文地址:http://www.cnblogs.com/LennyKwok/p/4339606.html