国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IOS中的動畫——CoreAnimation

2019-11-14 19:12:45
字體:
來源:轉載
供稿:網友
一、基礎動畫 CABasicAnimation
1  //初始化方式    CABasicAnimation * cabase=[CABasicAnimation animation];2  //通過keyPath設置需要實現動畫的屬性,此處設為boundscabase.keyPath=@"bounds";3 //通過toValue設置動畫結束時候的狀態cabase.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 10, 100)]; //通過byValue設置每次改變的范圍cabase.byValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 10, 100)];//設置開始時候的狀態    cabase.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];4  //設置動畫持續的時間cabase.duration=2;    //保存動畫   cabase.fillMode=kCAFillModeForwards;    //保存設置不取消   cabase.removedOnCompletion=NO;[_layer addAnimation:cabase forKey:nil];

   案例:通過基礎動畫實現仿射變換動畫

CABasicAnimation * cabase=[CABasicAnimation animation];cabase.keyPath=@"transform";cabase.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 2, 1)];cabase.duration=2;cabase.fillMode=kCAFillModeForwards;      cabase.removedOnCompletion=NO;[_layer addAnimation:cabase forKey:nil];
二、關鍵幀動畫
1  //初始化方式CAKeyframeAnimation * keyfram=[CAKeyframeAnimation animation];2  //通過keyPath設置需要實現動畫的屬性,此處設為positionkeyfram.keyPath=@"position";3 //設置動畫的需要經過的點    CGPoint  p1=CGPointZero;    CGPoint  p2=CGPointMake(150, 0);    CGPoint  p3=CGPointMake(150, 150);    CGPoint  p4=CGPointMake(0, 150);    CGPoint  p5=CGPointZero;    NSValue * v1=[NSValue valueWithCGPoint:p1];    NSValue * v2=[NSValue valueWithCGPoint:p2];    NSValue * v3=[NSValue valueWithCGPoint:p3];    NSValue * v4=[NSValue valueWithCGPoint:p4];NSValue * v5=[NSValue valueWithCGPoint:p5];4 //將對應的值添加到動畫并且設置動畫保留    keyfram.values=@[v1,v2,v3,v4,v5];    keyfram.duration=1;    keyfram.fillMode=kCAFillModeForwards;    keyfram.removedOnCompletion=NO;[_layer addAnimation:keyfram forKey:nil];

  案例:通過關鍵幀動畫實現圖片搖擺

  CAKeyframeAnimation * anima=[CAKeyframeAnimation animation];    //通過設置放射變換的角度來實現    anima.keyPath=@"transform.rotation";    float p1=4/180.0*M_PI;    anima.duration=0.2;    anima.values=@[@(-p1),@(p1),@(-p1)];    anima.fillMode=kCAFillModeForwards;    anima.removedOnCompletion=NO;    anima.repeatCount=MAXFLOAT;    [_layer addAnimation:anima forKey:nil];_layer.transform=CATransform3DMakeRotation(M_PI, 0, 0, 0);
三、轉場動畫
1  //初始化方式CATransition * tran=[CATransition animation];2  //設置動畫效果tran.type=@"rippleEffect";//常用效果kCATransitionFadekCATransitionMoveInkCATransitionPushkCATransitionReveal3 //設置動畫方向tran.subtype=kCATransitionFromLeft;//動畫方向kCATransitionFromRightkCATransitionFromLeftkCATransitionFromTopkCATransitionFromBottom4 //設置動畫保留以及動畫時長  tran.fillMode=kCAFillModeForwards;  tran.removedOnCompletion=NO;  tran.duration=1;  [self.myImageView.layer addAnimation:tran forKey:nil];
四、UIView封裝動畫

  UIKit直接將動畫集成到UIView類中,當內部的一些屬性發生改變時,UIView將為這些改變提供動畫支持。執行動畫所需要的工作由UIView類自動完成,但仍要在希望執行動畫時通知視圖,為此需要將改變屬性的代碼放在[UIViewbeginAnimations:nil context:nil]和[UIView commitAnimations]之間

   1、常見方法解析:

//設置動畫代理+ (void)setAnimationDelegate:(id)delegate   //設置當動畫即將開始時,執行delegate對象的selector,并且把beginAnimations:context:中傳入的參數傳進selector  +(void)setAnimationWillStartSelector:(SEL)selector   //設置動畫結束時調用方法+ (void)setAnimationDidStopSelector:(SEL)selector //設置動畫持續時間+(void)setAnimationDuration:(NSTimeInterval)duration  //設置動畫延遲+ (void)setAnimationDelay:(NSTimeInterval)delay   //設置動畫開始時間+ (void)setAnimationStartDate:(NSDate *)startDate//設置動畫節奏+ (void)setAnimationCurve:(UIViewAnimationCurve)curve //設置動畫重復次數+ (void)setAnimationRepeatCount:(float)repeatCount //如果設置為YES,代表動畫每次重復執行的效果會跟上一次相反+(void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses // 設置視圖view的過渡效果, transition指定過渡類型, cache設置YES代表使用視圖緩存,性能較好+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache 

  2、案例

   //旋轉動畫    [UIView beginAnimations:@"roate" context:nil];    [UIView setAnimationCurve:UIViewAnimationCurveEaSEOut];    [UIView setAnimationDuration:1.5];     [UIView setAnimationDelegate:self];    _view.transform=CGAffineTransformRotate(_view.transform, M_PI_2);    [UIView setAnimationDidStopSelector:@selector(endAnimate)];[UIView commitAnimations];    //轉場動畫[UIView beginAnimations:@"transition" context:nil];    [UIView setAnimationCurve:UIViewAnimationCurveLinear];    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_mainView cache:YES];    [UIView setAnimationDuration:1.5];    NSInteger index1=[_mainView.subviews indexOfObject:_view];    NSInteger index2=[_mainView.subviews indexOfObject:_view2];    [_mainView exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2];    [UIView commitAnimations];

 

作者:杰瑞教育
出處:http://www.survivalescaperooms.com/jerehedu/ 
本文版權歸煙臺杰瑞教育科技有限公司和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 秭归县| 滨海县| 长汀县| 华坪县| 夏河县| 新化县| 福建省| 拜城县| 永城市| 荔浦县| 成安县| 沅江市| 长海县| 青浦区| 温州市| 沈丘县| 兰溪市| 施甸县| 云和县| 亚东县| 聂拉木县| 新郑市| 兴安盟| 崇信县| 隆回县| 云霄县| 长葛市| 秦安县| 东乡族自治县| 奈曼旗| 南皮县| 漳平市| 卢氏县| 哈尔滨市| 天峻县| 扶沟县| 两当县| 密山市| 普定县| 平定县| 仙居县|