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

CALaer形变和阴影

时间:2015-03-10 17:27:12      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:calayer   动画   

//  
//  CALayerTransformViewController.m
//  CALayerTransformController
//
//  Created by xiaoyao on 15/3/10.
//  Copyright (c) 2015年 lijien. All rights reserved.
//

#import "CALayerTransformViewController.h"

#define PHOTO_HEOGHT 150

@interface CALayerTransformViewController ()

@end

@implementation CALayerTransformViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  [self calayerAndTransform];
}

- (void)calayerAndTransform {
  // 阴影图层
  CALayer *shadowLayer = [[CALayer alloc] init];
  shadowLayer.bounds = CGRectMake(0, 0, PHOTO_HEOGHT, PHOTO_HEOGHT);
  shadowLayer.position = CGPointMake(160, 200);
  shadowLayer.cornerRadius = PHOTO_HEOGHT / 2;
  shadowLayer.shadowColor = [UIColor grayColor].CGColor;
  shadowLayer.shadowOpacity = 1;
  shadowLayer.shadowOffset = CGSizeMake(2, 1);
  shadowLayer.borderWidth = 2;
  shadowLayer.borderColor = [UIColor whiteColor].CGColor;
  [self.view.layer addSublayer:shadowLayer];
  
  // 形变图层
  CALayer *layer = [[CALayer alloc] init];
  layer.bounds = shadowLayer.bounds;
  layer.position = shadowLayer.position;
  layer.backgroundColor = [UIColor redColor].CGColor;
  layer.cornerRadius = shadowLayer.cornerRadius;
  layer.masksToBounds = YES;
  layer.borderColor =  [UIColor whiteColor].CGColor;
  layer.borderWidth = shadowLayer.borderWidth;
  [self.view.layer addSublayer:layer];
  
  // 解决图片的倒立问题
  layer.transform = CATransform3DMakeRotation(M_PI, 1, 0, 0);
  layer.delegate = self;
  
  [layer setNeedsDisplay];
}

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
  UIImage *image = [UIImage imageNamed:@"photo.png"];
  CGContextDrawImage(ctx, CGRectMake(0, 0, PHOTO_HEOGHT, PHOTO_HEOGHT), image.CGImage);
}
@end

CALaer形变和阴影

标签:calayer   动画   

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

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