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

首頁 > 系統 > iOS > 正文

實現IOS等待時動畫效果的操作分解步驟

2020-02-19 15:55:06
字體:
來源:轉載
供稿:網友

使用IOS查詢頁面時間太長的時候,設計師們為了改善用戶體驗,最常用的方法之一是在查詢等待時添加動態等待效果,那么實現IOS等待時動畫效果的操作分解步驟大家都了解嗎?下面就讓武林技術頻道小編帶你一起來了解一下吧!

效果圖如下:

源代碼可以網上找開源項目Coding.net,上面的效果原理為兩張圖片組合,外面那個則為動畫轉動,里面的圖標則是透明度的變化;主要代碼如下:

1:把它封裝在EaseLoadingView里面

@interface EaseLoadingView : UIView@property (strong, nonatomic) UIImageView *loopView, *monkeyView;@property (assign, nonatomic, readonly) BOOL isLoading;- (void)startAnimating;- (void)stopAnimating;@end@interface EaseLoadingView ()@property (nonatomic, assign) CGFloat loopAngle, monkeyAlpha, angleStep, alphaStep;@end@implementation EaseLoadingView- (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) {  self.backgroundColor = [UIColor clearColor];  _loopView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading_loop"]];  _monkeyView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading_monkey"]];  [_loopView setCenter:self.center];  [_monkeyView setCenter:self.center];  [self addSubview:_loopView];  [self addSubview:_monkeyView];  [_loopView mas_makeConstraints:^(MASConstraintMaker *make) {   make.center.equalTo(self);  }];  [_monkeyView mas_makeConstraints:^(MASConstraintMaker *make) {   make.center.equalTo(self);  }];  _loopAngle = 0.0;  _monkeyAlpha = 1.0;  _angleStep = 360/3;  _alphaStep = 1.0/3.0; } return self;}- (void)startAnimating{ self.hidden = NO; if (_isLoading) {  return; } _isLoading = YES; [self loadingAnimation];}- (void)stopAnimating{ self.hidden = YES; _isLoading = NO;}- (void)loadingAnimation{ static CGFloat duration = 0.25f; _loopAngle += _angleStep; if (_monkeyAlpha >= 1.0 || _monkeyAlpha 

注意loadingAnimation這里面有動作的處理及透明度的處理,當停止加載后把它自個從當前的視圖去除;

2:UIView (Common)在UIView擴展類里

?

#pragma mark LoadingView@property (strong, nonatomic) EaseLoadingView *loadingView;- (void)beginLoading;- (void)endLoading;@end- (void)setLoadingView:(EaseLoadingView *)loadingView{ [self willChangeValueForKey:@"LoadingViewKey"]; objc_setAssociatedObject(self, &LoadingViewKey,        loadingView,        OBJC_ASSOCIATION_RETAIN_NONATOMIC); [self didChangeValueForKey:@"LoadingViewKey"];}- (EaseLoadingView *)loadingView{ return objc_getAssociatedObject(self, &LoadingViewKey);}- (void)beginLoading{ for (UIView *aView in [self.blankPageContainer subviews]) {  if ([aView isKindOfClass:[EaseBlankPageView class]] && !aView.hidden) {   return;  } } if (!self.loadingView) { //初始化LoadingView  self.loadingView = [[EaseLoadingView alloc] initWithFrame:self.bounds]; } [self addSubview:self.loadingView]; [self.loadingView mas_makeConstraints:^(MASConstraintMaker *make) {  make.self.edges.equalTo(self); }]; [self.loadingView startAnimating];}- (void)endLoading{ if (self.loadingView) {  [self.loadingView stopAnimating]; }}

注意:cocoa的KVO模型中,有兩種通知觀察者的方式,自動通知和手動通知。顧名思義,自動通知由cocoa在屬性值變化時自動通知觀察者,而手動通知需要在值變化時調用 willChangeValueForKey:和didChangeValueForKey: 方法通知調用者。

3:使用頁面調用

?

- (void)sendRequest{ [self.view beginLoading]; __weak typeof(self) weakSelf = self; [[Coding_NetAPIManager sharedManager] request_CodeFile:_myCodeFile withPro:_myProject andBlock:^(id data, NSError *error) {  [weakSelf.view endLoading];  if (data) {   weakSelf.myCodeFile = data;   [weakSelf refreshCodeViewData];  }  [weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(data != nil) hasError:(error != nil) reloadButtonBlock:^(id sender) {   [weakSelf sendRequest];  }]; }];}

其中[self.view beginLoading]跟[weakSelf.view endLoading]就可以調用動畫效果;

補充:另一種是有很多不同的圖片組成的動畫效果,可以用每一張圖片然后FOR遍歷組成出動作效果;

//設置普通狀態的動畫圖片 NSMutableArray *idleImages = [NSMutableArray array]; for (NSUInteger i = 1; i

上文是關于實現IOS等待時動畫效果的操作分解步驟的介紹,相信大家都有了一定的了解,想要了解更多的相關介紹,請繼續關注武林技術頻道網吧!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 连山| 汤原县| 湖北省| 静海县| 永州市| 海盐县| 新巴尔虎右旗| 揭阳市| 平凉市| 鹿邑县| 简阳市| 铁力市| 澜沧| 鄂托克旗| 清丰县| 宣化县| 四子王旗| 道孚县| 玉山县| 密山市| 炎陵县| 屏边| 绥中县| 湘潭市| 宜章县| 马龙县| 准格尔旗| 贡山| 那曲县| 宽城| 襄垣县| 陈巴尔虎旗| 石嘴山市| 巴林左旗| 方城县| 贵州省| 玛多县| 南溪县| 遂昌县| 渝中区| 北票市|