欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS動(dòng)畫解析之圓球加載動(dòng)畫XLBallLoading的實(shí)現(xiàn)

 更新時(shí)間:2017年11月04日 16:17:42   作者:孟憲亮  
加載動(dòng)畫對(duì)大家來說都不陌生,我們?cè)谄綍r(shí)都會(huì)遇見,開發(fā)中也必不可少,所以下面這篇文章主要給大家介紹了關(guān)于iOS動(dòng)畫解析之圓球加載動(dòng)畫XLBallLoading實(shí)現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。

前言

當(dāng)網(wǎng)頁(yè)的頁(yè)面大小較大,用戶加載可能需要較長(zhǎng)的時(shí)間,在這些情況下,我們一般會(huì)用到(加載)loading動(dòng)畫,提示于用戶頁(yè)面在加載中,本文將詳細(xì)給大家介紹關(guān)于iOS圓球加載動(dòng)畫XLBallLoading實(shí)現(xiàn)的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。

一、顯示效果

二、原理分析

1、拆解動(dòng)畫

從效果圖來看,動(dòng)畫可拆解成兩部分:放大動(dòng)畫、位移動(dòng)畫

放大動(dòng)畫 比較簡(jiǎn)單,這里主要來分析一下位移動(dòng)畫

(1)、先去掉縮放效果:

屏蔽放大效果

(2)、去掉其中的一個(gè)圓球

現(xiàn)在基本可以看出主要原理就是讓其中一個(gè)圓球繞另一個(gè)球做圓弧運(yùn)動(dòng),只要確定一個(gè)圓球的運(yùn)動(dòng)軌跡,另一個(gè)圓球和它左相對(duì)運(yùn)動(dòng)即可。下面咱們重點(diǎn)說一下這個(gè)圓弧運(yùn)動(dòng)的原理。

2、圓弧運(yùn)動(dòng)

為了方便觀察我們先放慢一下這個(gè)動(dòng)畫,然后添加輔助線:

放慢后的效果圖

從圖中可以看出,藍(lán)色球主要經(jīng)過了三段軌跡

  • 第一段:從左邊緣逆時(shí)針運(yùn)動(dòng)180°到灰色球的右側(cè)
  • 第二段:從灰色球右側(cè)貼著灰色球逆時(shí)針運(yùn)動(dòng)180°到其左側(cè)
  • 第三段:從灰色球左側(cè)返回起始位置

既然分析出了運(yùn)動(dòng)軌跡,下面實(shí)現(xiàn)起來就方便了

第一段:藍(lán)色球以A為起點(diǎn),沿圓心O逆時(shí)針運(yùn)動(dòng)到B點(diǎn)

第二段:藍(lán)色球以B為起點(diǎn)繞圓心P運(yùn)動(dòng)到C點(diǎn)

第三段:從C點(diǎn)返回原點(diǎn)

三、實(shí)現(xiàn)代碼

1、第一段運(yùn)動(dòng):

確定起始點(diǎn)、圓心、半徑,讓藍(lán)色小球繞大圓

 //動(dòng)畫容器的寬度
 CGFloat width = _ballContainer.bounds.size.width;
 //小圓半徑
 CGFloat r = (_ball1.bounds.size.width)*ballScale/2.0f;
 //大圓半徑
 CGFloat R = (width/2 + r)/2.0;
 UIBezierPath *path1 = [UIBezierPath bezierPath];
 //設(shè)置起始位置
 [path1 moveToPoint:_ball1.center];
 //畫大圓(第一段的運(yùn)動(dòng)軌跡)
 [path1 addArcWithCenter:CGPointMake(R + r, width/2) radius:R startAngle:M_PI endAngle:M_PI*2 clockwise:NO];

2、第二段運(yùn)動(dòng)

以灰色小球中心為圓心,以其直徑為半徑繞小圓,并拼接兩段曲線

//畫小圓
 UIBezierPath *path1_1 = [UIBezierPath bezierPath];
 //圓心為灰色小球的中心 半徑為灰色小球的半徑
 [path1_1 addArcWithCenter:CGPointMake(width/2, width/2) radius:r*2 startAngle:M_PI*2 endAngle:M_PI clockwise:NO];
 [path1 appendPath:path1_1];

3、第三段運(yùn)動(dòng)

//回到原處
 [path1 addLineToPoint:_ball1.center];

4、位移動(dòng)畫

利用關(guān)鍵幀動(dòng)畫實(shí)現(xiàn)小球沿設(shè)置好的貝塞爾曲線移動(dòng)

 //執(zhí)行動(dòng)畫
 CAKeyframeAnimation *animation1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
 animation1.path = path1.CGPath;
 animation1.removedOnCompletion = YES;
 animation1.duration = [self animationDuration];
 animation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
 [_ball1.layer addAnimation:animation1 forKey:@"animation1"];

5、縮放動(dòng)畫

在每次位移動(dòng)畫開始時(shí)執(zhí)行縮放動(dòng)畫

-(void)animationDidStart:(CAAnimation *)anim{

 CGFloat delay = 0.3f;
 CGFloat duration = [self animationDuration]/2 - delay;

 [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseOut| UIViewAnimationOptionBeginFromCurrentState animations:^{
  _ball1.transform = CGAffineTransformMakeScale(ballScale, ballScale);
  _ball2.transform = CGAffineTransformMakeScale(ballScale, ballScale);
  _ball3.transform = CGAffineTransformMakeScale(ballScale, ballScale);
 } completion:^(BOOL finished) {
  [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseInOut| UIViewAnimationOptionBeginFromCurrentState animations:^{
   _ball1.transform = CGAffineTransformIdentity;
   _ball2.transform = CGAffineTransformIdentity;
   _ball3.transform = CGAffineTransformIdentity;
  } completion:nil];
 }];
}

6、動(dòng)畫循環(huán)

在每次動(dòng)畫結(jié)束時(shí)從新執(zhí)行動(dòng)畫

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
 if (_stopAnimationByUser) {return;}
 [self startPathAnimate];
}

源碼下載

github

本地下載

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論