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

IOS等待時(shí)動(dòng)畫效果的實(shí)現(xiàn)

 更新時(shí)間:2015年08月10日 10:58:11   作者:踏浪帥  
查詢時(shí)間有長有短,為了增強(qiáng)用戶體驗(yàn)度,目前用的比較多的手段之一是查詢等待時(shí)添加一個(gè)動(dòng)態(tài)等待效果,這篇文章主要介紹IOS等待時(shí)動(dòng)畫效果的實(shí)現(xiàn),有需要的朋友可以參考下

查詢時(shí)間或長或短,為了提升用戶體驗(yàn),目前用的比較多的手段之一就是查詢等待時(shí)添加一個(gè)動(dòng)態(tài)等待效果。當(dāng)我們在請求網(wǎng)絡(luò)時(shí)加載頁面時(shí)有個(gè)動(dòng)作效果,效果圖如下:

源代碼可以網(wǎng)上找開源項(xiàng)目Coding.net,上面的效果原理為兩張圖片組合,外面那個(gè)則為動(dòng)畫轉(zhuǎn)動(dòng),里面的圖標(biāo)則是透明度的變化;主要代碼如下:

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 <= 0.0) {
  _alphaStep = -_alphaStep;
 }
 _monkeyAlpha += _alphaStep;
 [UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
  CGAffineTransform loopAngleTransform = CGAffineTransformMakeRotation(_loopAngle * (M_PI / 180.0f));
  _loopView.transform = loopAngleTransform;
  _monkeyView.alpha = _monkeyAlpha;
 } completion:^(BOOL finished) {
  if (_isLoading && [self superview] != nil) {
   [self loadingAnimation];
  }else{
   [self removeFromSuperview];
   _loopAngle = 0.0;
   _monkeyAlpha = 1,0;
   _alphaStep = ABS(_alphaStep);
   CGAffineTransform loopAngleTransform = CGAffineTransformMakeRotation(_loopAngle * (M_PI / 180.0f));
   _loopView.transform = loopAngleTransform;
   _monkeyView.alpha = _monkeyAlpha;
  }
 }];
}
@end

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

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

#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模型中,有兩種通知觀察者的方式,自動(dòng)通知和手動(dòng)通知。顧名思義,自動(dòng)通知由cocoa在屬性值變化時(shí)自動(dòng)通知觀察者,而手動(dòng)通知需要在值變化時(shí)調(diào)用 willChangeValueForKey:和didChangeValueForKey: 方法通知調(diào)用者。

3:使用頁面調(diào)用

- (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]就可以調(diào)用動(dòng)畫效果;

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

//設(shè)置普通狀態(tài)的動(dòng)畫圖片
 NSMutableArray *idleImages = [NSMutableArray array];
 for (NSUInteger i = 1; i<=60; ++i) {
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"dropdown_anim__000%zd",i]];
    [idleImages addObject:image];
  [idleImages addObject:image];
 }

以上內(nèi)容是本文通過IOS等待時(shí)動(dòng)畫效果的實(shí)現(xiàn),希望對大家有所幫助。

相關(guān)文章

  • 全面解析iOS中同步請求、異步請求、GET請求、POST請求

    全面解析iOS中同步請求、異步請求、GET請求、POST請求

    通過本文給大家全面解析了iOS中同步請求、異步請求、GET請求、POST請求,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧
    2016-08-08
  • iOS開發(fā)中Date Picker和UITool Bar控件的使用簡介

    iOS開發(fā)中Date Picker和UITool Bar控件的使用簡介

    這篇文章主要介紹了iOS開發(fā)中Date Picker和UITool Bar控件的使用簡介,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2016-01-01
  • 詳解iOS中position:fixed吸底時(shí)的滑動(dòng)出現(xiàn)抖動(dòng)的解決方案

    詳解iOS中position:fixed吸底時(shí)的滑動(dòng)出現(xiàn)抖動(dòng)的解決方案

    這篇文章主要介紹了詳解iOS中position:fixed吸底時(shí)的滑動(dòng)出現(xiàn)抖動(dòng)的解決方案,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-12-12
  • iOS中在APP內(nèi)加入AppStore評分功能的實(shí)現(xiàn)方法

    iOS中在APP內(nèi)加入AppStore評分功能的實(shí)現(xiàn)方法

    這篇文章主要介紹了iOS中在APP內(nèi)加入AppStore評分功能的實(shí)現(xiàn)方法,文中筆者給大家整理了三種方式,大家可以根據(jù)自己的需求選擇,需要的朋友可以參考下
    2017-11-11
  • 詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題

    詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題

    這篇文章主要介紹了詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • iOS?xcconfig編寫示例教程

    iOS?xcconfig編寫示例教程

    這篇文章主要為大家介紹了iOS?xcconfig編寫示例教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • safari調(diào)試iOS app web頁面的步驟

    safari調(diào)試iOS app web頁面的步驟

    這篇文章主要為大家詳細(xì)介紹了safari調(diào)試iOS app web頁面的步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • IOS開發(fā)之路--C語言預(yù)處理

    IOS開發(fā)之路--C語言預(yù)處理

    由于預(yù)處理指令是在編譯之前就進(jìn)行了,因此很多時(shí)候它要比在程序運(yùn)行時(shí)進(jìn)行操作效率高。在C語言中包括三類預(yù)處理指令,今天將一一介紹:宏定義、條件編譯、文件包含
    2014-08-08
  • iOS 實(shí)現(xiàn)跑馬燈效果的方法示例

    iOS 實(shí)現(xiàn)跑馬燈效果的方法示例

    可能說起跑馬燈,大家第一個(gè)會(huì)想到的就是山寨機(jī)。但接下來這篇文章介紹的跑馬燈和那個(gè)跑馬燈是不一樣滴。在iOS中,跑馬燈是指label上的字自動(dòng)滾動(dòng),形成類似跑馬燈似的條幅。下面通過這篇文章我們來一起看看iOS 實(shí)現(xiàn)跑馬燈效果的方法,有需要的朋友們可以參考借鑒。
    2017-01-01
  • iOS實(shí)現(xiàn)簡易的計(jì)算器

    iOS實(shí)現(xiàn)簡易的計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)簡易的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01

最新評論