IOS的 普通動畫可使用UIKit提供的動畫方式;
復雜動畫可使用Core Animation。
1、 通過動畫上下文使用UIKit動畫
-(void)animationOfUIKit {
UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
[self.view addSubview:redView];
//開始動畫
[UIView beginAnimations:@"test" context:nil];
//動畫時長
[UIView setAnimationDuration:1];
//設置動畫淡入淡出
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
/*
*要進行動畫設置的地方
*/
redView.backgroundColor=[UIColor blueColor];
redView.frame=CGRectMake(50, 50, 200, 200);
redView.alpha=0.5;
//動畫結束
[UIView commitAnimations];
}2、通過代碼塊使用UIKit動畫
-(void)animationOfBlock {
//初始化一個View,用來顯示動畫
UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
[self.view addSubview:redView];
[UIView animateWithDuration:1 //時長
delay:0 //延遲時間
options:UIViewAnimationOptionTransitionFlipFromLeft//動畫效果
animations:^{
//動畫設置區域
redView.backgroundColor=[UIColor blueColor];
redView.frame=CGRectMake(50, 50, 200, 200);
redView.alpha=0.5;
} completion:^(BOOL finish){
//動畫結束時調用
}];
}3、UIView的,翻轉、旋轉,偏移,翻頁,縮放,取反的動畫效果
CoreGraphics框架中的CGAffineTransform類可用于設定UIView的transform屬性,控制視圖的縮放、旋轉和平移等操作 (另稱為 放射變換矩陣),這種動畫都是針對視圖的原定最初位置的中心點為起始參照進行相應操作的,在操作結束之后可對設置量進行還原:
view.transform=CGAffineTransformIdentity;
翻轉的動畫
//開始動畫 [UIView beginAnimations:@"doflip" context:nil]; //設置時常 [UIView setAnimationDuration:1]; //設置動畫淡入淡出 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //設置代理 [UIView setAnimationDelegate:self]; //設置翻轉方向 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:manImageView cache:YES]; //動畫結束 [UIView commitAnimations];
旋轉動畫
//創建一個CGAffineTransform transform對象 CGAffineTransform transform; //設置旋轉度數 transform = CGAffineTransformRotate(manImageView.transform,M_PI/6.0); //動畫開始 [UIView beginAnimations:@"rotate" context:nil ]; //動畫時常 [UIView setAnimationDuration:2]; //添加代理 [UIView setAnimationDelegate:self]; //獲取transform的值 [manImageView setTransform:transform]; //關閉動畫 [UIView commitAnimations];
偏移動畫
[UIView beginAnimations:@"move" context:nil]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; //改變它的frame的x,y的值 manImageView.frame=CGRectMake(100,100, 120,100); [UIView commitAnimations];
翻頁動畫
[UIView beginAnimations:@"curlUp" context:nil]; //指定動畫曲線類型,該枚舉是默認的,線性的是勻速的 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //設置動畫時常 [UIView setAnimationDuration:1]; [UIView setAnimationDelegate:self]; //設置翻頁的方向 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:manImageView cache:YES]; //關閉動畫 [UIView commitAnimations];
縮放動畫
CGAffineTransform transform = CGAffineTransformScale(manImageView.transform,1.2,1.2); [UIView beginAnimations:@"scale" context:nil]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; [manImageView setTransform:transform]; [UIView commitAnimations];
取反的動畫效果是根據當前的動畫取他的相反的動畫
CGAffineTransform transform = CGAffineTransformInvert(manImageView.transform); [UIView beginAnimations:@"Invert" context:nil]; [UIView setAnimationDuration:2];//動畫時常 [UIView setAnimationDelegate:self]; [manImageView setTransform:transform];//獲取改變后的view的transform [UIView commitAnimations];//關閉動畫
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。