The implementation of IOS wait time animation effect _ios

Source: Internet
Author: User

Query time or long or short, in order to enhance the user experience, the current use of more than one of the means of query waiting to add a dynamic wait effect. We have an action effect when we load the page while requesting the network, and the effect is as follows:

Source code can find open source project Coding.net, the above effect principle is two picture combination, outside that is animation rotation, inside the icon is the change of transparency; The main code is as follows:

1: Wrap it inside the 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

Note that there is a process of action and transparency in the loadinganimation, which is removed from the current view when the load is stopped;

2:uiview (Common) in UIView extension class

#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]] &AMP;&A
  MP;!aview.hidden) {return;
 } if (!self.loadingview) {//Initialize 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];

 }
}

Note: In the KVO model of cocoa, there are two ways to notify the Observer, automatic notification and manual notification. As the name suggests, automatic notification is automatically notified by cocoa when the value of the property changes, and manual notification needs to call Willchangevalueforkey: and Didchangevalueforkey When the value changes: Method notifies the caller.

3: Using page calls

-(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];}];}


where [Self.view beginloading] and [Weakself.view endloading] can invoke the animation effect;

Add: The other is a lot of different pictures of the animation effect, you can use each picture and then for the traversal composition of the action effect;

Set the normal state of the animated picture
 nsmutablearray *idleimages = [Nsmutablearray array];
 for (Nsuinteger i = 1; i<=60; ++i) {
    uiimage *image = [uiimage imagenamed:[nsstring stringwithformat:@] Dropdown_ani M__000%zd ", I]];
    [Idleimages Addobject:image];
  [Idleimages addobject:image];
 }

The above content is this article through the iOS waits the animation effect realization, hoped has the help to everybody.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.