仿網(wǎng)易嚴(yán)選iOS下拉刷新動(dòng)畫(兩個(gè)小圓球繞中心旋轉(zhuǎn))

類似網(wǎng)易嚴(yán)選的上拉刷新動(dòng)畫(兩個(gè)小圓球繞中心旋轉(zhuǎn))

(自己截了幾張圖? 隨便用PS做了幾張簡(jiǎn)單動(dòng)畫)

項(xiàng)目需求要做一個(gè)類似網(wǎng)易嚴(yán)選的上拉刷新動(dòng)畫((下拉到一定角度的時(shí)候兩個(gè)小圓球分離 然后開始旋轉(zhuǎn) 上推的時(shí)候兩個(gè)小圓球緩慢重合起來(lái)))

實(shí)現(xiàn)原理

自定義UIView,然后添加兩個(gè)畫出兩個(gè)小圓球,分離動(dòng)畫用最簡(jiǎn)單的UIView動(dòng)畫就好了甥郑,動(dòng)起來(lái)是通過(guò)CAAnimation動(dòng)畫因?yàn)樯婕暗臇|西不是很難,下面就直接貼代碼了

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

先建個(gè)UIView 然后再添加兩個(gè)小圓球

LQHeaderView.h

```

#import

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define QUAN_Y 8

@interface LQHeaderView : UIView

@property (nonatomic , strong) UIView *leftView;

@property (nonatomic,strong) UIView * rightView;

-(void)viewwithwidth:(CGFloat)width;

@end

```


LQHeaderView.m

```

#import "LQHeaderView.h"

@interface LQHeaderView()

@end

@implementation LQHeaderView

-(void)viewwithwidth:(CGFloat)width{

CGFloat with =? width-12-10;

_leftView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2, with,QUAN_Y,QUAN_Y)];

_leftView.backgroundColor = [UIColor redColor];

_leftView.layer.masksToBounds = YES;

_leftView.layer.cornerRadius =QUAN_Y/2;

[self? addSubview:_leftView];

_rightView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2, with,QUAN_Y,QUAN_Y)];

_rightView.backgroundColor = [UIColor blueColor];

_rightView.layer.masksToBounds = YES;

_rightView.layer.cornerRadius =QUAN_Y/2;

[self? addSubview:_rightView];

}

@end

```

因?yàn)槲乙龅氖窍吕瓌?dòng)畫(下拉到一定角度的時(shí)候兩個(gè)小圓球分離 然后開始旋轉(zhuǎn) 上推的時(shí)候兩個(gè)小圓球緩慢重合起來(lái))我們項(xiàng)目上拉控件集成的MJRefresh 所以需要繼承MJRefreshStateHeader

MJLQHeader.h

```

#import "MJRefreshStateHeader.h"

#import "LQHeaderView.h"

#define QUAN_Y 8

@interface MJLQHeader : MJRefreshStateHeader

@end

```

MJLQHeader

```

#import "MJLQHeader.h"

@interface MJLQHeader(){

LQHeaderView *_gifView;

CGFloat BGRefreshViewH;

CAAnimationGroup * groupTwoAnimation ;

CAAnimationGroup * groupOneAnimation ;

int stats;

}

@end

@implementation MJLQHeader

-(void)create{

self.mj_h = 30+5+5+5;

LQHeaderView *gifView = [[LQHeaderView alloc] init];

gifView.mj_x = 0;

gifView.mj_y = 0;

gifView.mj_w = self.mj_w;

gifView.mj_h = self.mj_h;

[self addSubview:_gifView = gifView];

[gifView viewwithwidth:self.mj_h];

BGRefreshViewH =? self.mj_h -12-10;

_gifView.contentMode = UIViewContentModeCenter;

}

#pragma mark - 實(shí)現(xiàn)父類的方法

- (void)prepare

{

[super prepare];

self.mj_h = 30+5+5+5;

[self create];

// 初始化間距

//? ? self.labelLeftInset = 20;

}

- (void)placeSubviews

{

[super placeSubviews];

}

- (void)setState:(MJRefreshState)state

{

MJRefreshCheckState

// 根據(jù)狀態(tài)做事情

if(state == MJRefreshStatePulling){

[self fenli];

}else if(state == MJRefreshStateRefreshing){

[self oneYuanDian];

[self twoYuanDian];

}else if (state == MJRefreshStateIdle && stats!=102) {

[self stop];

}? else if (state == MJRefreshStateIdle && stats ==102) {

[self fenli];;

}

}

//分離動(dòng)畫

-(void)fenli

{

stats =5;

[UIView animateWithDuration:0.5

animations:^{

_gifView.leftView.frame = CGRectMake(SCREEN_WIDTH/2+9,BGRefreshViewH, QUAN_Y, QUAN_Y);

_gifView.rightView.frame = CGRectMake(SCREEN_WIDTH/2-9,BGRefreshViewH, QUAN_Y, QUAN_Y);

}

completion:^(BOOL finished) {

}];

}

//重合動(dòng)畫

-(void)stop{

stats=5;

[UIView animateWithDuration:0.5 // 動(dòng)畫時(shí)長(zhǎng)

animations:^{

[_gifView.rightView.layer removeAllAnimations];

[_gifView.leftView.layer removeAllAnimations];

_gifView.leftView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

_gifView.rightView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

}

completion:^(BOOL finished) {

// 動(dòng)畫完成后執(zhí)行

// code...https://git.coding.net/Super-Rabbit/ShunLianDemo.git

//? ? ? ? ? ? ? ? ? ? ? ? [self oneYuanDian];

//? ? ? ? ? ? ? ? ? ? ? ? [self twoYuanDian];

_gifView.leftView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

_gifView.rightView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

}];

}

//動(dòng)畫開始

-(void)oneYuanDian{

//? ? //位移動(dòng)畫

CAKeyframeAnimation *anima1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];

UIBezierPath *arcPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(SCREEN_WIDTH/2, BGRefreshViewH) radius:9 startAngle:0 endAngle:M_PI*2 clockwise:YES];

anima1.path = arcPath.CGPath;

//組動(dòng)畫

groupOneAnimation = [CAAnimationGroup animation];

groupOneAnimation.animations = [NSArray arrayWithObjects:anima1, nil];

groupOneAnimation.duration = 0.9f;

groupOneAnimation.repeatCount= HUGE_VALF;

[groupOneAnimation setRemovedOnCompletion:NO];

[_gifView.leftView.layer addAnimation:groupOneAnimation forKey:@"groupAnimation"];

}

-(void)twoYuanDian{

//? ? //位移動(dòng)畫

CAKeyframeAnimation *anima1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];

UIBezierPath *arcPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(SCREEN_WIDTH/2, BGRefreshViewH) radius:9 startAngle:M_PI endAngle:M_PI*3 clockwise:YES];

anima1.path = arcPath.CGPath;

//組動(dòng)畫

groupTwoAnimation = [CAAnimationGroup animation];

groupTwoAnimation.animations = [NSArray arrayWithObjects:anima1, nil];

groupTwoAnimation.duration = 0.9f;

groupTwoAnimation.repeatCount= HUGE_VALF;

[groupTwoAnimation setRemovedOnCompletion:NO];

[_gifView.rightView.layer addAnimation:groupTwoAnimation forKey:@"groupAnimation"];

}

- (void)setPullingPercent:(CGFloat)pullingPercent

{

[super setPullingPercent:pullingPercent];

NSLog(@"pullingPercent? %lf",pullingPercent);

NSString * string = [NSString stringWithFormat:@"%lf",pullingPercent];

if(pullingPercent>1.5 && stats==5 ){

[self oneYuanDian];

[self twoYuanDian];

stats=100;

}if([string isEqualToString:@"0.000000"]){

[self stopppp];

}

}

- (void)endRefreshing

{

[super endRefreshing];

stats =102;

}

//重合動(dòng)畫

-(void)stopppp{

stats=5;

[UIView animateWithDuration:0.5 // 動(dòng)畫時(shí)長(zhǎng)

animations:^{

[_gifView.rightView.layer removeAllAnimations];

[_gifView.leftView.layer removeAllAnimations];

//? ? ? ? ? ? ? ? ? ? ? ? _gifView.leftView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

//? ? ? ? ? ? ? ? ? ? ? ? _gifView.rightView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

}

completion:^(BOOL finished) {

// 動(dòng)畫完成后執(zhí)行

// code...https://git.coding.net/Super-Rabbit/ShunLianDemo.git

//? ? ? ? ? ? ? ? ? ? ? ? [self oneYuanDian];

//? ? ? ? ? ? ? ? ? ? ? ? [self twoYuanDian];

_gifView.leftView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

_gifView.rightView.frame = CGRectMake(SCREEN_WIDTH/2,BGRefreshViewH, QUAN_Y, QUAN_Y);

}];

}

@end

```

寫的不是很清楚? git? 上傳了個(gè)? https://github.com/gjjggg/WYLQMJRefresh.git

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末富稻,一起剝皮案震驚了整個(gè)濱河市边坤,隨后出現(xiàn)的幾起案子挺庞,更是在濱河造成了極大的恐慌谁尸,老刑警劉巖舅踪,帶你破解...
    沈念sama閱讀 217,084評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異良蛮,居然都是意外死亡抽碌,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門决瞳,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)货徙,“玉大人,你說(shuō)我怎么就攤上這事皮胡∑破牛” “怎么了?”我有些...
    開封第一講書人閱讀 163,450評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵胸囱,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我瀑梗,道長(zhǎng)烹笔,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,322評(píng)論 1 293
  • 正文 為了忘掉前任抛丽,我火速辦了婚禮谤职,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘亿鲜。我一直安慰自己允蜈,他們只是感情好冤吨,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評(píng)論 6 390
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著饶套,像睡著了一般漩蟆。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上妓蛮,一...
    開封第一講書人閱讀 51,274評(píng)論 1 300
  • 那天怠李,我揣著相機(jī)與錄音,去河邊找鬼蛤克。 笑死捺癞,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的构挤。 我是一名探鬼主播髓介,決...
    沈念sama閱讀 40,126評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼筋现!你這毒婦竟也來(lái)了唐础?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,980評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤夫否,失蹤者是張志新(化名)和其女友劉穎彻犁,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體凰慈,經(jīng)...
    沈念sama閱讀 45,414評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡汞幢,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了微谓。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片森篷。...
    茶點(diǎn)故事閱讀 39,773評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖豺型,靈堂內(nèi)的尸體忽然破棺而出仲智,到底是詐尸還是另有隱情,我是刑警寧澤姻氨,帶...
    沈念sama閱讀 35,470評(píng)論 5 344
  • 正文 年R本政府宣布钓辆,位于F島的核電站,受9級(jí)特大地震影響肴焊,放射性物質(zhì)發(fā)生泄漏前联。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評(píng)論 3 327
  • 文/蒙蒙 一娶眷、第九天 我趴在偏房一處隱蔽的房頂上張望似嗤。 院中可真熱鬧,春花似錦届宠、人聲如沸烁落。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)伤塌。三九已至灯萍,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間寸谜,已是汗流浹背竟稳。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留熊痴,地道東北人他爸。 一個(gè)月前我還...
    沈念sama閱讀 47,865評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像果善,于是被迫代替她去往敵國(guó)和親诊笤。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評(píng)論 2 354

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