标签:
// // CALayerController.m // CALayer // // Created by xiaoyao on 15/3/5. // Copyright (c) 2015年 lijien. All rights reserved. // #import "CALayerController.h" #define WIDTH 50 @interface CALayerController () @end @implementation CALayerController - (void)viewDidLoad { [super viewDidLoad]; [self drawMyLayer]; } - (void)drawMyLayer { CGSize size = [UIScreen mainScreen].bounds.size; CALayer *layer = [[CALayer alloc] init]; layer.position = CGPointMake(size.width / 2, size.height / 2); layer.bounds = CGRectMake(0, 0, WIDTH, WIDTH); layer.backgroundColor = [UIColor colorWithRed:0 green:146 / 255 blue:1 alpha:1].CGColor; layer.cornerRadius = WIDTH / 2; layer.shadowColor = [UIColor grayColor].CGColor; layer.shadowOffset = CGSizeMake(2, 2); layer.shadowOpacity = .9; [self.view.layer addSublayer:layer]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CALayer *layer = self.view.layer.sublayers[0]; UITouch *touch = [touches anyObject]; CGFloat width = layer.bounds.size.width; if (width == WIDTH) { width = WIDTH * 4; } else { width = WIDTH; } layer.bounds = CGRectMake(0, 0, width, width); layer.cornerRadius = width / 2; layer.position = [touch locationInView:self.view]; } @end
标签:
原文地址:http://blog.csdn.net/u010606986/article/details/44082795