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

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

CoreAnimation核心動畫一(一些常用屬性和方法)

2019-11-14 18:17:03
字體:
來源:轉載
供稿:網友

1、常用屬性:

 frame   bounds   center   alpha    Transition 過渡    transform 動畫效果

2、常用方法:

 +(void)setAnimationDelegate:(id)delegate;

 +(void)setAnimationWillStartSelector:(SEL)selector; 當動畫結束的時候,執行delegate對象的selector,并且把beginAnimations:context:中傳入的參數傳進selector

 + (void)setAnimationDidStopSelector:(SEL)selector;  當動畫結束時,執行delegate對象的selector,并且把beginAnimations:context:中傳入的參數傳進selector

 

 + (void)setAnimationDuration:(NSTimeInterval)duration;   動畫的持續時間,秒為單位

 

 + (void)setAnimationDelay:(NSTimeInterval)delay;  動畫延遲delay秒后再開始

 

 + (void)setAnimationStartDate:(NSDate *)startDate;   動畫的開始時間,默認為now

 

 + (void)setAnimationCurve:(UIViewAnimationCurve)curve;  動畫的節奏控制(過渡)

 

 + (void)setAnimationRepeatCount:(float)repeatCount;  動畫的重復次數

 

 + (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;  如果設置為YES,代表動畫每次重復執行的效果會跟上一次相反

 

 + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;  設置視圖view的過渡效果, transition指定過渡類型, cache設置YES代表使用視圖緩存,性能較好

 

  1 #import "ViewController.h"  2   3 @interface ViewController ()  4 {  5     UIImageView *imageView;  6 }  7 @end  8   9 @implementation ViewController 10  11 - (void)viewDidLoad { 12     [super viewDidLoad]; 13  14     imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; 15     imageView.image = [UIImage imageNamed:@"7.jpg"]; 16 //    imageView.contentMode = UIViewContentModeScaleaspectFit; 17     [self.view addSubview:imageView]; 18      19     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 20     button.frame = CGRectMake(0, 0, 100, 40); 21     button.center = self.view.center; 22     button.backgroundColor = [UIColor brownColor]; 23     [button addTarget:self action:@selector(viewAnimation3) forControlEvents:UIControlEventTouchUpInside]; 24     [self.view addSubview:button]; 25  26  27 } 28  29  30 #PRagma mark -- 1、frame bounds center alpha --- 31 - (void)viewAnimation1 { 32 #pragma mark - 方法1 33 //    在一段時間內 執行完命令 34 //    [UIView animateWithDuration:3 animations:^{ 35 //        imageView.alpha = 0.5; 36 //    }]; 37      38 #pragma mark - 方法2 39 //  開始動畫 40     [UIView beginAnimations:@"animation" context:nil]; 41      42 //    這只動畫的持續時間 43     [UIView setAnimationDuration:3]; 44      45 //    ..... 動畫效果 46     imageView.alpha = 0.5; 47     imageView.bounds = CGRectMake(0, 0, 100, 100); 48     imageView.center = CGPointMake(50, 200); 49 //    imageView.frame = CGRectMake(100, 100, 100, 100); 50      51 //    提交動畫  會去執行動畫 52     [UIView commitAnimations]; 53 } 54  55 #pragma mark - 2、Transition 56 /* 57  typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { 58  UIViewAnimationTransitionNone, 59  UIViewAnimationTransitionFlipFromLeft, 從左面翻轉 60  UIViewAnimationTransitionFlipFromRight,從右面翻轉 61  UIViewAnimationTransitionCurlUp, 向上翻頁 62  UIViewAnimationTransitionCurlDown,向下翻頁 63  }; 64  */ 65 - (void)viewAnimation2 { 66 //    開始動畫 67     [UIView beginAnimations:nil context:nil]; 68 //    設置動畫持續時間 69 //    [UIView setAnimationDuration:3]; 70 //    設置 UIView 的過渡動畫 71     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:imageView cache:YES]; 72      73 #pragma mark - 3、UIViewAnimationCurve 74     /* 75      typedef NS_ENUM(NSInteger, UIViewAnimationCurve) { 76      UIViewAnimationCurveEaseInOut,         // slow at beginning and end  慢進慢出 77      UIViewAnimationCurveEaseIn,            // slow at beginning  快進 78      UIViewAnimationCurveEaSEOut,           // slow at end  快出 79      UIViewAnimationCurveLinear   勻速 80      }; 81      */ 82     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 83 //    設置 代理(檢測動畫結束) 84     [UIView setAnimationDelegate:self]; 85     [UIView setAnimationDidStopSelector:@selector(finishAnimation)]; 86 //    提交動畫 87     [UIView commitAnimations]; 88      89 } 90  91 //  動畫結束之后觸發的方法 92 - (void)finishAnimation { 93     [UIView beginAnimations:@"o" context:nil]; 94     [UIView setAnimationDuration:3]; 95     imageView.alpha = 0.1; 96     imageView.bounds = CGRectZero; 97     imageView.center = CGPointMake(100, 100); 98      99     [UIView commitAnimations];100 }101 102 #pragma mark - 4、transform103 /*104  imageView.transform=CGAffineTransformScale(imageView.transform, 0.5, 0.5); // 實現的是放大和縮小imageView.transform=CGAffineTransformRotate(imageView.transform, M_PI_4); //實現的是旋轉 imageView.transform=CGAffineTransformTranslate(imageView.transform, 20, 0); //實現的是平移105  */106 - (void)viewAnimation3 {107     108     [UIView beginAnimations:@"animation" context:nil];109     [UIView setAnimationDuration:3];110 //    transform 如果沒有還原transform 他會保持 改變后的模樣111     imageView.transform = CGAffineTransformScale(imageView.transform, 0.5, 0.5);112     113     [UIView setAnimationDelegate:self];114     [UIView setAnimationDidStopSelector:@selector(restore)];115     [UIView commitAnimations];116     117 }118 119 - (void)restore {120     [UIView animateWithDuration:3 animations:^{121         imageView.transform = CGAffineTransformIdentity;122 123     }];124 }

模擬器效果截圖:

方法一效果圖:

 

方法二效果圖:

方法三效果圖:

 


上一篇:iOS-音頻和視頻

下一篇:Category

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凌海市| 成安县| 邹平县| 白朗县| 连江县| 上蔡县| 恩施市| 句容市| 犍为县| 东安县| 永春县| 常山县| 定襄县| 嘉义市| 公安县| 调兵山市| 乌拉特中旗| 修水县| 龙游县| 财经| 吐鲁番市| 边坝县| 鄂伦春自治旗| 河南省| 蓝田县| 肇州县| 沂水县| 玉溪市| 稷山县| 金阳县| 遂宁市| 禹城市| 杭锦后旗| 抚顺县| 黔西县| 曲沃县| 定远县| 南安市| 林州市| 桑日县| 桑日县|