OObjective-c CALayer 动画
2015-12-22 00:00
573 查看
ViewController.m文件
// // ViewController.m // 动画 // // Created by DC017 on 15/12/22. // Copyright © 2015年 DC017. All rights reserved. // #import "ViewController.h" //宏定义 #define W [UIScreen mainScreen].bounds.size.width #define H [UIScreen mainScreen].bounds.size.height #define YANSE(r,g,b,a) [UIColor colorWithRed:r/225.0 green:g/225.0 blue:b/225.0 alpha:a] //设置layer的宽和高 #define LayerWidth 50 @interface ViewController (){ CALayer * layer1; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; layer1=[[CALayer alloc]init]; //设置宽度 layer1.bounds=CGRectMake(0, 0, LayerWidth, LayerWidth); //设置中心点的位置 layer1.position=CGPointMake(W/2, H/2); //设置背景颜色 layer1.backgroundColor=YANSE(144, 80, 122, 1).CGColor; //添加 [self.view.layer addSublayer:layer1]; //设置圆角 layer1.cornerRadius=LayerWidth/2; //设置阴影 //设置阴影颜色 layer1.shadowColor=[UIColor grayColor].CGColor; layer1.shadowOffset=CGSizeMake(2, 2); layer1.shadowOpacity=0.8;//设置透明度 //描点(x,y 范围都是0-1) // layer1.anchorPoint=CGPointMake(1, 1); NSLog(@"%@",layer1); } -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //获取点击位置 UITouch * touch=[touches anyObject]; //打印点击位置 NSLog(@"点击位置是:%@", NSStringFromCGPoint([touch locationInView:self.view])); //打印layer的对象地址 NSLog(@"%@",self.view.layer.sublayers); //获取对象 CALayer * layer2=self.view.layer.sublayers[2]; //将layer移到点击位置 //点击位置通过locationInView来获取 layer2.position=[touch locationInView:self.view]; //放大 CGFloat width=layer2.bounds.size.width; if (width==LayerWidth) { width=LayerWidth*4; }else{ width=LayerWidth; } layer2.bounds=CGRectMake(0, 0, width, width); layer2.cornerRadius=width/2;//圆角是根据当前图形宽度来设置 } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- objective-c 转场动画
- OBjective-c 弹簧效果
- objective-c 逐帧动画
- Object-C 一些关键字的理解 @synchronized、__block、class等。。。
- “object name conflicts in archive”的解决办法
- Mybatis3源码分析(12)-Sql解析执行-MetaObject
- 【Objective-C学习记录】第二十天
- Android中两个activity之间传递list<object>
- 关于Objective-C 错误代码 Expression is not assignable 引发的问题
- Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks程序(Python)配置问题总结
- Objective-c语言_协议
- Objective-c语言_延展
- Objective-c语言_类目
- dYSM分析崩溃日志
- #Objective - C - Fifth-Day 三大容器(数组、字典、集合)常用语法归纳总结
- JAVA 1.6源码解析-Object类
- The constness of a method should makes sense from outside the object
- Informatica Connection Objects
- Objective-c语言_文件基本操作
- Java基础系列六、IDE+Object+String