Ios Custom Animation effects, ios Custom Animation
During the development process, you may encounter various scenarios that need to wait until the loading is successful before the data can be displayed. The following is a Custom Animation loading view effect.
The following figure shows the effect of loading in UIViewController:
-(Void) viewDidLoad {[super viewDidLoad]; // change the view background color to yellow self. view. backgroundColor = [UIColor yellowColor]; // In self. load the prompt box [[BIDActivityNote sharedInstance] AddActivityView: self. view]; // after a delay of 3 minutes, remove the prompt box dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (3 * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {[[BIDActivityNote sharedInstance] RemoveActivityView] ;});}
BIDActivityNote. h implementation code
//// BIDActivityNote. h // MobileShop /// Created by eJiupi on 15-7-23. // Copyright (c) 2014 xujinzhong. all rights reserved. // # import <Foundation/Foundation. h> @ interface BIDActivityNote: NSObject + (BIDActivityNote *) sharedInstance;-(void) AddActivityView :( UIView *) subView;-(void) RemoveActivityView; @ end
BIDActivityNote. m code implementation:
//// BIDActivityNote. m // MobileShop /// Created by eJiupi on 15-7-23. // Copyright (c) 2014 xujinzhong. all rights reserved. // # import "BIDActivityNote. h "@ interface BIDActivityNote () @ property (strong, nonatomic) UIView * subView; @ property (strong, nonatomic) UIActivityIndicatorView * act; @ end @ implementation BIDActivityNote + (BIDActivityNote *) sharedInstance {static BIDActivityNote * instance = nil; if (instance = nil) {instance = [[BIDActivityNote alloc] init];} return instance;}-(id) init {self = [super init]; if (self) {NSInteger w = [UIScreen mainScreen]. bounds. size. width; NSInteger h = [UIScreen mainScreen]. bounds. size. height; self. subView = [[UIView alloc] initWithFrame: CGRectMake (0, 0, w, h)]; self. subView. backgroundColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 0.5]; self. act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge]; // you can only set the center, but not the self size. act. center = CGPointMake (w/2.f, h/2.f); // set the color self of the activity indicator. act. color = [UIColor whiteColor]; [self. act startAnimating]; // starts to rotate [self. act stopAnimating]; // end rotation // [self. act setHidesWhenStopped: YES]; // hide [self. subView addSubview: self. act];} return self;}-(void) AddActivityView :( UIView *) subView {// start [self. act startAnimating]; [subView addSubview: self. subView]; // implement the animation effect self. subView. transform = CGAffineTransformScale (self. subView. transform, 0, 0); [UIView animateWithDuration: 2 animations: ^ {self. subView. transform = CGAffineTransformIdentity;}];}-(void) RemoveActivityView {[UIView animateWithDuration: 0.7 animations: ^ {self. subView. transform = CGAffineTransformScale (self. subView. transform, 0, 0);} completion: ^ (BOOL bfinished) {if (bfinished) {// stop [self. act stopAnimating]; [self. subView removeFromSuperview] ;}}] ;}@ end