ios動畫

_lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

? ? _lable.text = @"果然小行家";

? ? _lable.textAlignment = 1;

? ? _lable.center = self.view.center;

? ? _lable.textColor = [UIColor redColor];

? ? _lable.layer.cornerRadius = 50;

? ? _lable.layer.backgroundColor = [UIColor cyanColor].CGColor;

? ? [self.view addSubview:_lable];


//? ? UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

//? ? button.frame = CGRectMake(100, 100, 60, 40);

//? ? [button setTitle:@"暫停" forState:0];//實現(xiàn)動畫的暫停

//? ? [button setTitleColor:[UIColor redColor] forState:0];

//? ? [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];

//? ? [self.view addSubview:button];

//

//? ? UIButton *resumeButton = [UIButton buttonWithType:UIButtonTypeCustom];

//? ? [resumeButton setTitle:@"重啟" forState:0];

//? ? [resumeButton setTitleColor:[UIColor blueColor] forState:0];

//? ? resumeButton.frame = CGRectMake(200, 100, 60, 40);

//? ? [resumeButton addTarget:self action:@selector(handleResumeBtn:) forControlEvents:UIControlEventTouchUpInside];

//? ? [self.view addSubview:resumeButton];


?一 ? //通過定時器實現(xiàn)旋轉(zhuǎn)------------旋轉(zhuǎn)

//? ? _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(actionTimer:) userInfo:nil repeats:YES];

//? ? [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];

//? ? [_timer fire];



二 ? ?//實現(xiàn)位置的移動

//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"transform"];

//? ? CATransform3D form = CATransform3DMakeTranslation(-350, -100, 0);//控制位置

//? ? animal.toValue = [NSValue valueWithCATransform3D:form];

//? ? animal.duration = 1;

//? ? animal.removedOnCompletion = NO;

//? ? animal.fillMode = kCAFillModeForwards;

//? ? [_lable.layer addAnimation:animal forKey:nil];


三 ? ?//大小? 實現(xiàn)大小的變化

//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"transform"];

//? ? CATransform3D form = CATransform3DMakeScale(1.2, 1.2, 1);

//? ? animal.toValue = [NSValue valueWithCATransform3D:form];

//? ? animal.duration = 0.5;

//? ? animal.repeatCount = MAXFLOAT;

//? ? animal.autoreverses = YES;

//? ? [_lable.layer addAnimation:animal forKey:nil];



四 ? ?//實現(xiàn)大小、位置的變化通過bounds缀雳、position來實現(xiàn)

? /*

? ? //bounds

//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"bounds"];

//? ? animal.duration = 2;

//? ? animal.toValue = [NSValue valueWithCGRect:CGRectMake(-200, 0, 10, 10)];

//? ? [_lable.layer addAnimation:animal forKey:nil];


五 ? ? //position

//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"position"];

//? ? animal.toValue = [NSValue valueWithCGPoint:CGPointMake(250, 500)];

//? ? //取消反彈

//? ? animal.removedOnCompletion = NO;

//? ? animal.duration = 1.5;

//? ? animal.repeatCount = 3;

//? ? animal.fillMode = kCAFillModeForwards;

//? ? [_lable.layer addAnimation:animal forKey:nil];

? ? */


? ? 六 ? ? ? ? ? ? ? ?/****** CAKeyframeAnimation--->關(guān)鍵幀動畫 ****/

? ? //多步動畫? 來回晃動的動畫效果

//? ? CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];

//? ? animation.values = @[@0, @50, @-10, @50, @0];

//? ? //設(shè)置每一幀執(zhí)行的時間長短 這個的取值為0-1虫蝶,代表占用時間的比例

//? ? animation.keyTimes = @[@0, @(1 / 6.0), @(3 / 6.0), @(5 / 6.0), @1];

//? ? animation.duration = 1;

////? ? animation.repeatCount = 10;

//? ? animation.repeatCount = 10000;

//? ? //設(shè)置幀的中間值如何計算

//? ? animation.calculationMode = kCAAnimationPaced;

//? ? //additive 這個屬性確定動畫執(zhí)行的狀態(tài)是否疊加在控件的原狀態(tài)上

//? ? //默認設(shè)置為NO娇哆,如果我們執(zhí)行兩次位置移動的動畫,會從同一位置執(zhí)行兩次

//? ? //如果設(shè)置為YES,則會在第一次執(zhí)行的基礎(chǔ)上執(zhí)行第二次動畫

//? ? animation.additive = YES;

//? ? [_lable.layer addAnimation:animation forKey:nil];

//? ? _lable.layer.zPosition = 1;


七 ? ?//位置

? ? //沿貝塞爾曲線的動畫

? ? //這個方法將創(chuàng)建橢圓形路徑

? ? //? ? ? ? ? ? ? 實現(xiàn)一個控件圍繞一個點轉(zhuǎn)圈的效果

//? ? CGRect boundingRect = CGRectMake(-40, 0, 100, 100);

//? ? UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:boundingRect cornerRadius:50];

//

//? ? CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

//? ? //設(shè)置一個路徑

//? ? animation.path = path.CGPath;

//? ? animation.duration = 4;

//? ? animation.additive = YES;

//? ? animation.repeatCount = HUGE_VALF;

//? ? animation.calculationMode = kCAAnimationPaced;

//? ? animation.rotationMode = kCAAnimationRotateAuto;

//? ? [_lable.layer addAnimation:animation forKey:nil];



八 ? ? ? ? ? ?/********* CASpringAnimation---> 彈性動畫 ********/

//? ? CASpringAnimation *animation = [CASpringAnimation animationWithKeyPath:@"position"];

//? ? animation.toValue = [NSValue valueWithCGPoint:CGPointMake(175, 400)];

//

//? ? //質(zhì)量,影響圖層運動時的彈簧慣性倒信,質(zhì)量越大科贬,彈簧拉伸和壓縮的幅度越大

//? ? //如果把質(zhì)量改成10泳梆,則動畫的速度變慢,并且波動幅度變大

//? ? animation.mass = 3;

//

//? ? //阻尼系數(shù)榜掌,阻止彈簧伸縮的系數(shù)优妙,阻尼系數(shù)越大,停止越快

//? ? animation.damping = 30;

//? ? //初始速率憎账,動畫視圖的初始速度大小

//? ? animation.initialVelocity = 10;

//? ? //剛度? 剛度系數(shù)越大套硼,形變產(chǎn)生的力就越大,運動越快

//? ? animation.stiffness = 10;

//

//? ? animation.duration = 2;

//? ? animation.fillMode = kCAFillModeForwards;

//? ? animation.removedOnCompletion = NO;

//? ? [_lable.layer addAnimation:animation forKey:nil];



? ? 九 ? ? ? ?/**** CATransition--->轉(zhuǎn)場動畫 *****/


//? ? //定義個轉(zhuǎn)場動畫

? ? CATransition *animation = [CATransition animation];

? ? //轉(zhuǎn)場動畫持續(xù)時間

? ? animation.duration = 1;


? ? //轉(zhuǎn)場動畫類型

? ? animation.type = kCATransitionPush;

? ? //轉(zhuǎn)場動畫將去的方向

? ? animation.subtype = kCATransitionFromBottom;

? ? //添加動畫 (轉(zhuǎn)場動畫是添加在層上的動畫)

? ? [_lable.layer addAnimation:animation forKey:nil];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末胞皱,一起剝皮案震驚了整個濱河市邪意,隨后出現(xiàn)的幾起案子九妈,更是在濱河造成了極大的恐慌,老刑警劉巖雾鬼,帶你破解...
    沈念sama閱讀 222,183評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件萌朱,死亡現(xiàn)場離奇詭異,居然都是意外死亡策菜,警方通過查閱死者的電腦和手機晶疼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來又憨,“玉大人翠霍,你說我怎么就攤上這事〈垒海” “怎么了寒匙?”我有些...
    開封第一講書人閱讀 168,766評論 0 361
  • 文/不壞的土叔 我叫張陵,是天一觀的道長躏将。 經(jīng)常有香客問我蒋情,道長,這世上最難降的妖魔是什么耸携? 我笑而不...
    開封第一講書人閱讀 59,854評論 1 299
  • 正文 為了忘掉前任棵癣,我火速辦了婚禮,結(jié)果婚禮上夺衍,老公的妹妹穿的比我還像新娘狈谊。我一直安慰自己,他們只是感情好沟沙,可當我...
    茶點故事閱讀 68,871評論 6 398
  • 文/花漫 我一把揭開白布河劝。 她就那樣靜靜地躺著,像睡著了一般矛紫。 火紅的嫁衣襯著肌膚如雪赎瞎。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,457評論 1 311
  • 那天颊咬,我揣著相機與錄音务甥,去河邊找鬼。 笑死喳篇,一個胖子當著我的面吹牛敞临,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播麸澜,決...
    沈念sama閱讀 40,999評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼挺尿,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起编矾,我...
    開封第一講書人閱讀 39,914評論 0 277
  • 序言:老撾萬榮一對情侶失蹤熟史,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后窄俏,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體以故,經(jīng)...
    沈念sama閱讀 46,465評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,543評論 3 342
  • 正文 我和宋清朗相戀三年裆操,在試婚紗的時候發(fā)現(xiàn)自己被綠了怒详。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,675評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡踪区,死狀恐怖昆烁,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情缎岗,我是刑警寧澤静尼,帶...
    沈念sama閱讀 36,354評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站传泊,受9級特大地震影響鼠渺,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜眷细,卻給世界環(huán)境...
    茶點故事閱讀 42,029評論 3 335
  • 文/蒙蒙 一拦盹、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧溪椎,春花似錦虑灰、人聲如沸刨摩。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至歉秫,卻和暖如春蛾洛,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背雁芙。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評論 1 274
  • 我被黑心中介騙來泰國打工轧膘, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人却特。 一個月前我還...
    沈念sama閱讀 49,091評論 3 378
  • 正文 我出身青樓扶供,卻偏偏與公主長得像筛圆,于是被迫代替她去往敵國和親裂明。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,685評論 2 360

推薦閱讀更多精彩內(nèi)容