#import "ViewController.h"
#define originalWidth 100
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property(strong,nonatomic) CALayer* layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
/*self.redView.layer.borderWidth = 10;
self.redView.layer.borderColor = [UIColor greenColor].CGColor;
//阴影
self.redView.layer.shadowOffset = CGSizeMake(10, -10); self.redView.layer.shadowColor = [UIColor grayColor].CGColor; self.redView.layer.shadowOpacity = 0.7;
//圆角半径
self.redView.layer.cornerRadius = 15;
self.redView.layer.contents = (id)[UIImage imageNamed:@"0.jpg"].CGImage;//.CGImage很重要
//裁剪边角
//self.redView.clipsToBounds = YES;
//self.redView.layer.masksToBounds = YES; //会把阴影也裁剪掉
//self.redView.layer.position = CGPointMake(0, 0);//position默认是中间那个点(默认锚点)所在的坐标,如果要把锚点改成左上角点:
self.redView.layer.anchorPoint = CGPointMake(0, 0);//最大是(1,1) self.redView.layer.position = CGPointMake(0, 0);*/
CALayer* layer1 = [CALayer layer];
layer1.backgroundColor = [UIColor orangeColor].CGColor;
layer1.anchorPoint = CGPointMake(0, 0);
layer1.position = CGPointMake(0, 0);
layer1.bounds = CGRectMake(0, 0, originalWidth, originalWidth);
layer1.cornerRadius = originalWidth/2;
[self.view.layer addSublayer:layer1];
self.layer = layer1; }
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event{
//self.redView.layer.position = CGPointMake(10, 20);
//self.redView.layer.bounds = CGRectMake(0, 0, 100, 100);
//self.redView.layer.transform = CATransform3DTranslate(self.redView.layer.transform, 20, 20, 20);
//kvc设置属性:
//static int value = 20;
//value+= 20;
//[self.redView.layer setValue:[NSNumber numberWithInt:value] forKeyPath:@"transform.translation.x"];//平移
//[self.redView.layer setValue:[NSNumber numberWithDouble:1.2] forKeyPath:@"transform.scale.x"];
//放大self.layer
if (self.layer.bounds.size.width == originalWidth) {
static int newWidth = originalWidth*2;
self.layer.bounds = CGRectMake(0, 0, newWidth, newWidth);
self.layer.cornerRadius = newWidth/2;
}else{
//缩小layer
self.layer.bounds = CGRectMake(0, 0, originalWidth, originalWidth);
self.layer.cornerRadius = originalWidth/2;
}
}
@end
CALayer 隐式动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 浅谈CALayer的隐式动画及事务 一、前言 本文是为了后续直播App送礼大动画实战演练做铺垫, 浅谈CALaye...
- RedRain的简书:http://www.jianshu.com/users/29e03e6ff407/late...
- 1.每个UIView上都有一个自带的layer,我们称他们为root layer(根层) 2.所有的非根层都存在隐...