ViewController.m文件
//
// ViewController.m
// 动画
//
// Created by DC017 on 15/12/22.
// Copyright © 2015年 DC017. All rights reserved.
//
#import "ViewController.h"
//宏定义
#define W [UIScreen mainScreen].bounds.size.width
#define H [UIScreen mainScreen].bounds.size.height
#define YANSE(r,g,b,a) [UIColor colorWithRed:r/225.0 green:g/225.0 blue:b/225.0 alpha:a]
//设置layer的宽和高
#define LayerWidth 50
@interface ViewController (){
CALayer * layer1;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
layer1=[[CALayer alloc]init];
//设置宽度
layer1.bounds=CGRectMake(0, 0, LayerWidth, LayerWidth);
//设置中心点的位置
layer1.position=CGPointMake(W/2, H/2);
//设置背景颜色
layer1.backgroundColor=YANSE(144, 80, 122, 1).CGColor;
//添加
[self.view.layer addSublayer:layer1];
//设置圆角
layer1.cornerRadius=LayerWidth/2;
//设置阴影
//设置阴影颜色
layer1.shadowColor=[UIColor grayColor].CGColor;
layer1.shadowOffset=CGSizeMake(2, 2);
layer1.shadowOpacity=0.8;//设置透明度
//描点(x,y 范围都是0-1)
// layer1.anchorPoint=CGPointMake(1, 1);
NSLog(@"%@",layer1);
}
-(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 * layer2=self.view.layer.sublayers[2];
//将layer移到点击位置
//点击位置通过locationInView来获取
layer2.position=[touch locationInView:self.view];
//放大
CGFloat width=layer2.bounds.size.width;
if (width==LayerWidth) {
width=LayerWidth*4;
}else{
width=LayerWidth;
}
layer2.bounds=CGRectMake(0, 0, width, width);
layer2.cornerRadius=width/2;//圆角是根据当前图形宽度来设置
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end