CALayer上設置動畫,網絡編程

---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"]);}

相關文章
相關標籤/搜索