IOS CALayer

//spa

//  ViewController.m.net

//  CALayer12.223d

//orm

//  Created by dc008 on 15/12/22.内存

//  Copyright © 2015 崔晓宇. All rights reserved.ci

//get


#import "ViewController.h"it

#define WIDTH [UIScreen mainScreen].bounds.size.widthio

#define HEIGHT [UIScreen mainScreen].bounds.size.heightevent

#define LayerWidth 50

@interface ViewController ()



@end


@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)锚点 (xy的范围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