- (void)addLayer
{
myLayer = [[CALayer alloc]init];
myLayer.backgroundColor = [UIColor brownColor].CGColor;
myLayer.shadowColor = [UIColor yellowColor].CGColor;
//阴影的透明度 默认是0
myLayer.shadowOpacity = 1.0;
w = 100;
myLayer.bounds = CGRectMake(0, 0, w, w);
myLayer.position = self.view.center;
myLayer.cornerRadius = w/2;
myLayer.shadowOffset = CGSizeMake(-1, -1);
// myLayer.contents = (id)[[UIImage imageNamed:@"11.jpg"]CGImage];
// myLayer.contents =(id)[UIImage imageNamed:@"11.jpg"].CGImage;
// myLayer.masksToBounds = YES;
[self.view.layer addSublayer:myLayer];
}
- (void)addImageLayer
{
imageLayer = [[CALayer alloc]init];
imageLayer.bounds = myLayer.bounds;
imageLayer.position = myLayer.position;
imageLayer.cornerRadius = myLayer.cornerRadius;
imageLayer.contents =(id)[UIImage imageNamed:@"11.jpg"].CGImage;
imageLayer.masksToBounds = YES;
[self.view.layer addSublayer:imageLayer];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[self changeFormWith:[touch locationInView:self.view]];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[self changeFormWith:[touch locationInView:self.view]];
}
- (void)changeFormWith:(CGPoint )position
{
myLayer.position = position;
w = w ==100 ? 300:100;
myLayer.bounds = CGRectMake(0, 0, w, w);
myLayer.cornerRadius = w/2;
myLayer.backgroundColor = myLayer.backgroundColor== [UIColor brownColor].CGColor ? [UIColor redColor].CGColor:[UIColor brownColor].CGColor;
imageLayer.bounds = myLayer.bounds;
imageLayer.position = myLayer.position;
imageLayer.cornerRadius = myLayer.cornerRadius;
}