CALayer层添加动画以及初步网络请求

在昨天的基础上(初始化,设定frame,添加到UIView的layer),继续在上面添加图片背景或者动画效果。

添加图片,作为背景图片的话,是需要添加到根Layer 上:self.layer.contents=(id)image.CGImage;

如果是在背景图片上继续添加图片,则可以实例化一个UIImageView的对象,最后添加到Layer上[self.layer addSublayer:imageI.layer];

剩下的就是设置动画,在设置动画的同时可以加入点击、触摸等。

1、移动CAlayer(image.layer)的position

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"position"];

    animation.fromValue=[NSValue valueWithCGPoint:layer.position];//开始的位置   

    CGPoint   toPoint=layer.position;

    toPoint.x +=point.x-layer.frame.origin.x;//point.x-layer.frame.origin.x要移动的距离

    toPoint.y +=point.y-layer.frame.origin.y;

    animation.toValue=[NSValue valueWithCGPoint:toPoint];//结束移动位置

2、旋转(以 X 轴为例)

CABasicAnimation *rotate=[CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];

    rotate.fromValue=[NSNumber numberWithFloat:6*M_PI];旋转方式

3、放缩

        CABasicAnimation *scaoleAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.x"];//根据X轴进行放缩

        scaoleAnimation.duration=3;//持续时间

        scaoleAnimation.autoreverses=YES;//动画结束后再回到原来的位置继续播放

        scaoleAnimation.fromValue=[NSNumber numberWithFloat:1.0];开始大小

        scaoleAnimation.toValue=[NSNumber numberWithFloat:1.5];放缩倍数

        scaoleAnimation.fillMode=kCAFillModeForwards;

4、动画组合

       CAAnimationGroup *group=[CAAnimationGroup animation];//动画组

        group.autoreverses=YES;动画组结束后是否要回到原来位置继续播放

        group.duration=3.0;//持续时间

        group.animations=[NSArray arrayWithObjects:scaoleAnimation,nil];//数组添加要动画的对象

        group.repeatCount=NSNotFound;//默认是0,NSNotFound无限次播放

        group.fillMode=kCAFillModeForwards;动画结束后停在当前的状态,back-动画结束后返回到最初的状态

网络请求

1、获取网络地址

NSURL *url=[NSURL URLWithString:@"https://api.heweather.com/x3/citylist?search=allchina&key=8438216ce05b407b9677a02fc2cd78d2"];

https---安全版超文本传输协议

api.heweather.com/x3/citylist---API地址

?其后是参数

&参数与参数之间的连接符

2、发送请求

NSURLRequest *request=[NSURLRequest requestWithURL:url];

3、建立连接(返回值为NSData )

NSData *data=[NSURLConnection  sendSynchronousRequest:request returningResponse:&response error:nil];

4、解析数据

NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

 

 

 

转载于:https://my.oschina.net/whzhen1452/blog/741209

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值