项目结束了,一阵的空档期。想接点外包,但是怕公司突然又来项目。
于是便决定学习点东西------- Core Animation .
查了些资料以及视频。 找到一些比较好的视频,但是都是基于Swift编写的。
想着两种语言基本类似。 就决定把这套教程看完,将里面Swift语言都转成用OC编写。
---------------------------------------------------------------------------------------------------------
首先,在了解了部分的动画原理,以及各种资料。
从基层做起 --- 今天学习的是,Position Animation . 基本的位移动画。
简单来说,就是将一个View 从这边移到另一边
1.将 position animation 分为 三种情况:
1.横向移动
2.纵向移动
3.横纵向同时移动
在ViewController上 拖出三个View
记得将autolayout关掉。 不然动画的效果可能不会按自己预想的走
2.建立好控件连接
3.开始编写代码
-(void)positionAnimation
{
//动画持续时间 2s
[UIView animateWithDuration:2 animations:^{
CGPoint center = self.rect1.center;
CGPoint nextC = CGPointMake(self.view.bounds.size.width - center.x, center.y);
self.rect1.center = nextC;
}];
<span style="white-space:pre"> </span>//延时1S后,执行动画
[UIView animateWithDuration:1 delay:1 options:UIViewAnimationOptionCurveLinear animations:^{
CGPoint center = self.rect2.center;
CGPoint nextC = CGPointMake( center.x,self.view.bounds.size.height - center.y);
self.rect2.center = nextC;
} completion:nil];
//第三个动画的delay 不能再设置成1 应该是基于第二个的时间 + 1
[UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionCurveLinear animations:^{
CGPoint center = self.rect3.center;
CGPoint nextC = CGPointMake(self.view.bounds.size.width - center.x,self.view.bounds.size.height - center.y);
self.rect3.center = nextC;
} completion:nil];
}