// // 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
原文地址:http://blog.csdn.net/u010606986/article/details/44176353