iOS 基本動畫

1、改變frame

//開始做動畫,關鍵字“move”-->移動動畫

[UIView beginAnimations:@"move" context:nil];

//設置動畫的持續(xù)時間

[UIView setAnimationDuration:2];

[UIView setAnimationDelegate:self];

[UIView setAnimationWillStartSelector:@selector(animationWillStartHandle)];

_myView.frame = CGRectMake(130, 300, 165, 100);

[UIView commitAnimations];

2、改變color

//開始做動畫,關鍵字“color”-->改變顏色動畫

[UIView beginAnimations:@"color" context:nil];

3、改變透明度

//開始做動畫,關鍵字“alpha”-->改變透明度動畫

[UIView beginAnimations:@"alpha" context:nil];

4、翻轉

[UIView beginAnimations:@"doflip" context:nil];

[UIView setAnimationDuration:2];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_myView cache:YES];

[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];

[UIView commitAnimations];

5、旋轉

CGAffineTransform transform = CGAffineTransformRotate(_myView.transform, M_PI);

CGAffineTransform transform1 = CGAffineTransformMakeScale(0.5, 0.5);

[UIView beginAnimations:@"rotate" context:nil];

[UIView setAnimationDuration:2];

//-1:無限次

[UIView setAnimationRepeatCount:10];

_myView.transform = transform;

[UIView commitAnimations];

二、Spring

//Damping:0.0~1.0 阻尼系數(shù),越小的話強度越大

//SpringVelocity:初速度

[UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionRepeat animations:^{

_myImageView.backgroundColor = [UIColor grayColor];

} completion:^(BOOL finished) {

_myImageView.backgroundColor = [UIColor orangeColor];

NSLog(@"finish");

}];

三、block

1、

[UIView animateWithDuration:1 animations:^{

_myView.center = self.view.center;

}];

2、

//1、持續(xù)時間,2、要做的動畫 3、動畫完成之后的操作

[UIView animateWithDuration:3 animations:^{

_myView.center = self.view.center;

} completion:^(BOOL finished) {

NSLog(@"finish");

}];

3、

//block options包括了動畫的很多選項

[UIView animateWithDuration:3 delay:2 options:UIViewAnimationOptionRepeat animations:^{

_myView.center = self.view.center;

} completion:^(BOOL finished) {

NSLog(@"finish");

}];

4、

//UIView用block去做關鍵幀動畫

//在關鍵幀動畫里邊我們可以添加多個幀動畫

//starttime:相對總時間的百分比的一個時間;3*0.5=1.5秒的時間開始走第二個幀動畫

//每個幀動畫持續(xù)的時間 =(Duration-StartTime)* 總時間

[UIView animateKeyframesWithDuration:3 delay:1 options:UIViewKeyframeAnimationOptionRepeat animations:^{

[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.3 animations:^{

_myView.center = self.view.center;

_myView.backgroundColor = [UIColor grayColor];

}];

[UIView addKeyframeWithRelativeStartTime:0.3 relativeDuration:0.6 animations:^{

_myView.center = CGPointMake(200, 300);

_myView.backgroundColor = [UIColor orangeColor];

}];

[UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:1 animations:^{

_myView.center = CGPointMake(100, 400);

_myView.backgroundColor = [UIColor yellowColor];

}];

} completion:^(BOOL finished) {

NSLog(@"finishi");

}];

//動畫效果

/*

UIViewAnimationOptionLayoutSubviews:動畫過程中保證子視圖跟隨運動。

UIViewAnimationOptionAllowUserInteraction:動畫過程中允許用戶交互。

UIViewAnimationOptionBeginFromCurrentState:所有視圖從當前狀態(tài)開始運行。

UIViewAnimationOptionRepeat:重復運行動畫。

UIViewAnimationOptionAutoreverse :動畫運行到結束點后仍然以動畫方式回到初始點。********

UIViewAnimationOptionOverrideInheritedDuration:忽略嵌套動畫時間設置。

UIViewAnimationOptionOverrideInheritedCurve:忽略嵌套動畫速度設置。

UIViewAnimationOptionAllowAnimatedContent:動畫過程中重繪視圖(注意僅僅適用于轉場動畫)。

UIViewAnimationOptionShowHideTransitionViews:視圖切換時直接隱藏舊視圖、顯示新視圖,而不是將舊視圖從父視圖移除(僅僅適用于轉場動畫)

UIViewAnimationOptionOverrideInheritedOptions :不繼承父動畫設置或動畫類型。

2.動畫速度控制(可從其中選擇一個設置)

UIViewAnimationOptionCurveEaseInOut:動畫先緩慢,然后逐漸加速。

UIViewAnimationOptionCurveEaseIn :動畫逐漸變慢。

UIViewAnimationOptionCurveEaseOut:動畫逐漸加速。

UIViewAnimationOptionCurveLinear :動畫勻速執(zhí)行,默認值。

3.轉場類型(僅適用于轉場動畫設置,可以從中選擇一個進行設置,基本動畫、關鍵幀動畫不需要設置)

UIViewAnimationOptionTransitionNone:沒有轉場動畫效果。

UIViewAnimationOptionTransitionFlipFromLeft :從左側翻轉效果。

UIViewAnimationOptionTransitionFlipFromRight:從右側翻轉效果。

UIViewAnimationOptionTransitionCurlUp:向后翻頁的動畫過渡效果。

UIViewAnimationOptionTransitionCurlDown :向前翻頁的動畫過渡效果。

UIViewAnimationOptionTransitionCrossDissolve:舊視圖溶解消失顯示下一個新視圖的效果。

UIViewAnimationOptionTransitionFlipFromTop :從上方翻轉效果。

UIViewAnimationOptionTransitionFlipFromBottom:從底部翻轉效果。

*/

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 在iOS中隨處都可以看到絢麗的動畫效果,實現(xiàn)這些動畫的過程并不復雜,今天將帶大家一窺ios動畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,694評論 6 30
  • 在iOS實際開發(fā)中常用的動畫無非是以下四種:UIView動畫,核心動畫,幀動畫,自定義轉場動畫。 1.UIView...
    請叫我周小帥閱讀 3,324評論 1 23
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現(xiàn)這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,270評論 5 13
  • 先看看CAAnimation動畫的繼承結構 CAAnimation{ CAPropertyAnimation { ...
    時間不會倒著走閱讀 1,799評論 0 1
  • 前言 本文只要描述了iOS中的Core Animation(核心動畫:隱式動畫、顯示動畫)、貝塞爾曲線、UIVie...
    GitHubPorter閱讀 3,741評論 7 11

友情鏈接更多精彩內(nèi)容