首页 > 其他 > 详细

CALaer形变和阴影

时间:2015-03-10 17:24:04      阅读:251      评论:0      收藏:0      [点我收藏+]
//  
//  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形变和阴影

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!