iOS 自定義MJRefresh下拉重新整理動畫

2021-07-25 09:13:54 字數 3397 閱讀 8676

**實現如下

mjrefreshgifheader繼承自mj中的mjrefreshgifheader

#import

"mjrefreshgifheader.h"

@inte***ce customrefreshgifheader : mjrefreshgifheader

/** 設定state狀態下的動畫images 動畫持續時間duration*/

- (void)setimages:(nsarray *)images duration:(nstimeinterval)duration forstate:(mjrefreshstate)state;

- (void)setimages:(nsarray *)images forstate:(mjrefreshstate)state;

@end

#import "customrefreshgifheader.h"

#define width [uiscreen mainscreen].bounds.size.width

@inte***ce

customrefreshgifheader()

//一直左滑動的動畫

@property (nonatomic, strong) uiview *bgview;

//頂部的

@property (nonatomic, strong) uiimageview *topimage;

//自定義的重新整理提示狀態

@property (nonatomic, strong) uilabel *customstatuslable;

//跑動的imagev

@property (nonatomic, strong) uiimageview *customimagev;

//重寫父類

@property (strong, nonatomic) nsmutabledictionary *stateimages;

//重寫父類

@property (strong, nonatomic) nsmutabledictionary *statedurations;

@end

@implementation

customrefreshgifheader

#pragma mark - 懶載入

- (uiimageview *)topimage

return _topimage;

}- (uiview *)bgview

}return _bgview;

}- (uiimageview *)customimagev

return _customimagev;

}- (nsmutabledictionary *)stateimages

return _stateimages;

}- (nsmutabledictionary *)statedurations

return _statedurations;

}#pragma mark - 公共方法

//重寫動畫實現

- (void)setimages:(nsarray *)images duration:(nstimeinterval)duration forstate:(mjrefreshstate)state

}- (void)setimages:(nsarray *)images forstate:(mjrefreshstate)state

#pragma mark - 實現父類的方法

//初始化操作

- (void)prepare

///重寫mj百分比

- (void)setpullingpercent:(cgfloat)pullingpercent

}self

.customimagev

.frame = cgrectmake(width * 0.2 * pullingpercent , 60 * (1 - pullingpercent), 60 * pullingpercent, 60 * pullingpercent);

if (self

.bgview

.layer

.animationkeys

.count == 0)

nsarray *images = self

.stateimages[@(mjrefreshstateidle)];

if (self

.state != mjrefreshstateidle || images.count == 0) return;

[self

.customimagev stopanimating];

nsuinteger index = images.count * pullingpercent;

if (index >= images.count) index = images.count - 1;

self

.customimagev

.image = images[index];

[self layoutsubviews];

}//新的動畫frame不在根據placesubviews調整, 而是在拖動百分比中設定

- (void)placesubviews

- (void)setstate:(mjrefreshstate)state

//自定義位置的提示重新整理狀態始終跟父類的保持一致

self

.customstatuslable

.text = self

.statelabel

.text;

if (state == mjrefreshstatepulling || state == mjrefreshstaterefreshing) else

} else

if (state == mjrefreshstateidle)

}//主要效果就是實現當重新整理狀態完成時仍然能夠保持動畫完成.

- (void)endrefreshing completion:^(bool finished) );

});}];

}#pragma mark animation

- (cabasicanimation *)creatanimation

- (uilabel *)customstatuslable

return _customstatuslable;

}- (void)dealloc

@end

使用時只需將自定義的類拖進工程即可,跟原本mj使用方法相同.詳見demo

demo位址

ios自定義字型

提供字型檔案路徑,返回所需要字型 複製 uifont customfontwithpath nsstring path size cgfloat size 這樣就不需要在plist設定任何東西,只需要得到字型庫檔案的路徑,就可以取出對應的字型。上面的方法對於ttf otf的字型都有效,但是對於ttc...

iOS 自定義鬧鐘

ios 自定義鬧鐘 需求 從伺服器獲取到一組時間,都設定成鬧鈴,預設是每天迴圈不可修改,同時可以自定義鬧鈴,可選擇週幾迴圈。可以設定開啟關閉或者刪除。一.固定鬧鐘,每天迴圈。很簡單,將需要設定成鬧鐘的時間放入乙個陣列中,通過for迴圈設定成對應的本地推送,詳情見下面的 和注釋。void addloc...

IOS 自定義協議

在自定義協議的標頭檔案 h中 protocol nsdelegate optional 可選 void onoption nsstring pstr required 必須 void onrequired nsstring pstr end inte ce nsclass nsobject id d...