於是便決定學習點東西------- 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];
}