Ios Custom Animation effects, ios Custom Animation

Source: Internet
Author: User

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


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.