//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 ()
@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