码迷,mamicode.com
首页 > 其他好文 > 详细

CALayer常用属性,隐式动画

时间:2015-03-05 17:10:00      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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

CALayer常用属性,隐式动画

标签:

原文地址:http://blog.csdn.net/u010606986/article/details/44082795

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!