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:從底部翻轉效果。
*/