//
// ViewController.m
// CALayer12.22
//
// Created by dc008 on 15/12/22.
// Copyright © 2015年 崔晓宇. All rights reserved.
//
#import "ViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define LayerWidth 50
ViewController ()
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CALayer *layer = [[CALayer alloc]init];
//设置宽高
layer.bounds = CGRectMake(0, 0, LayerWidth, LayerWidth);
layer.position = CGPointMake(WIDTH/2.0, HEIGHT/2.0);
layer.backgroundColor = [UIColor colorWithRed:0.3 green:0.2 blue:0.7 alpha:0.7].CGColor;
[self.view.layer addSublayer:layer];
//设置圆角
layer.cornerRadius = LayerWidth/ 2;
//设置阴影
layer.shadowColor = [UIColor grayColor].CGColor;
//阴影偏移量
layer.shadowOffset = CGSizeMake(2, 2);
//阴影透明度(0-1),默认是0
layer.shadowOpacity = 0.9;
NSLog(@"CALayer内存地址:%@",layer);
//(mao)锚点 (x和y的范围0-1)
// layer.anchorPoint = CGPointMake(1, 1);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//获取点击位置
UITouch *touch = [touches anyObject];
NSLog(@"点击的位置是:%@",NSStringFromCGPoint([touch locationInView: self.view]));
//获取layer
NSLog(@"%@",self.view.layer.sublayers);
CALayer *layer = [[CALayer alloc]init];
layer = self.view.layer.sublayers[2];
layer.position = [touch locationInView:self.view];
//放大
CGFloat width = layer.bounds.size.width;
if (width == LayerWidth) {
width = LayerWidth * 4;
}
else {
width = LayerWidth;
}
layer.bounds = CGRectMake(0, 0, width, width);
layer.cornerRadius = width/2;//圆角是根据当前图形宽度来设置
}
@end