---CALayer上设置动画---编程
设置属性api
@property(nonatomic,strong)CALayer *layer;数组
初始化CALayer网络
_layer=[[CALayer alloc]init];测试
_layer.frame=CGRectMake(50, 50, 100, 100);动画
_layer.backgroundColor=[UIColor cyanColor].CGColor;atom
CALayer上添加图片url
UIImage *image =[UIImage imageNamed:@„韩非01.jpg"];code
_layer.contents=(id)(image.CGImage);orm
_layer.cornerRadius=5;
[self.view.layer addSublayer:_layer];
移动
CABasicAnimation *moveAnimation=[CABasicAnimation animationWithKeyPath:@„position"];
移动的初始值
moveAnimation.fromValue=[NSValue valueWithCGPoint:_layer.position];
CGPoint point=_layer.position; point.x+=180; point.y+=180;
移动的结束值
moveAnimation.toValue=[NSValue valueWithCGPoint:point];
开始动画
[_layer addAnimation:moveAnimation forKey:nil];
旋转
CABasicAnimation *rotateAnimation=[CABasicAnimation animationWithKeyPath:@„transform.rotation.x"];
旋转的初始值
rotateAnimation.fromValue=[NSNumber numberWithFloat:0.0];
旋转的结束值
rotateAnimation.toValue=[NSNumber numberWithFloat:6.2 * M_PI];
开始动画
[_layer addAnimation:rotateAnimation forKey:nil];
缩放
CABasicAnimation * scaleAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
缩放初始值
scaleAnimation.fromValue=[NSNumber numberWithFloat:1.0];
缩放结束值
scaleAnimation.toValue=[NSNumber numberWithFloat:3.0];
scaleAnimation.fillMode=kCAFillModeForwards;
开始动画
[_layer addAnimation:scaleAnimation forKey:nil];
实例化组合
CAAnimationGroup *group=[CAAnimationGroup animation];
组合
group.animations=[NSArray arrayWithObjects:moveAnimation,rotateAnimation,scaleAnimation ,nil];
group.fillMode=kCAFillModeBackwards;
开始动画
[_layer addAnimation:group forKey:nil];
————————————————————————————————————
CABasicAnimation,CAAnimationGroup的属性
-1-到达目的地以后,动画返回开始的值
group.autoreverses=YES;
-2-开始值到结束值花费的时间
group.duration=4.0;
-3-在指定的时间段完成后,动画就自动从上层移除了
group.removedOnCompletion=YES;
-4-动画播放的速度倍数
group.speed=1;
-5-指定开始播放动画的时间
group.beginTime=2;
-6-时间的偏移量
group.timeOffset=2;
-----网络编程-----
NSURL *url=[NSURL URLWithString:@"https://api.heweather.com/x3/citylist?search=allchina&key=48d7d68f454c4e01b3005e671c849990"];
请求数据
NSURLRequest *request=[NSURLRequest requestWithURL:url];
响应数据
NSURLResponse *response=nil;
JSON格式的数据
NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
测试是否有值
NSLog(@"data--%@",data);
字典接收JSON格式的数据
NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"dic--%@",dic);
数组接收字典的键
NSArray *array=dic[@"city_info"];
NSLog(@"array--%@",array);
遍历 for (id obj in array)
{NSLog(@"obj--%@",obj[@"city"]);}