IOS animation and ios animation effect

Source: Internet
Author: User

IOS animation and ios animation effect

//// ViewController. m // IOS-animation effects /// Created by wangtouwang on 15/5/5. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import "ViewController. h "# define kDuration 0.7 // animation duration (seconds) # define KS_HEIGTH [UIScreen mainScreen]. bounds. size. height # define KS_WIDTH [UIScreen mainScreen]. bounds. size. width @ interface ViewController () @ property (nonatomic, strong) UIView * imageView; @ end @ implementation ViewC Ontroller @ synthesize typeID; @ synthesize blueView; @ synthesize greenView;-(void) animationFunction :( UIButton *) btn {NSInteger index = btn. tag; CATransition * transition = [CATransition animation]; // The proxy transition. delegate = self; // duration transition. duration = kDuration; // type transition. type = [self getAnimationType: index]; // transition in the direction. subtype = [self getSubType]; // speed at which the animation starts and ends */transition. timingFu Nction = UIViewAnimationCurveEaseInOut; // event source NSInteger blue = [[_ imageView subviews] indexOfObject: blueView]; NSInteger green = [[_ imageView subviews] indexOfObject: greenView]; [_ imageView exchangeSubviewAtIndex: green withSubviewAtIndex: blue]; // start the animation [_ imageView. layer addAnimation: transition forKey: @ "animation"];}-(void) animationFunction2 :( UIButton *) btn {NSInteger index = btn. tag; CGContextRef c Ontext = UIGraphicsGetCurrentContext (); [UIView beginAnimations: nil context: context]; // start an animation block [UIView setAnimationDelegate: self]; // proxy [UIView setAnimationCurve: Custom]; // set the curve of the animation attribute change in the animation block. [UIView setAnimationDuration: kDuration]; // set the animation delay attribute in the animation block (in seconds) // set the transition switch (index) for the view in the animation Block) {case 10: [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView: self. view cache: YES]; break; case 9: [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView: self. view cache: YES]; break; case 12: [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView: self. view cache: YES]; break; case 11: [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: self. view cache: YES]; break; default: break;} // event source NSInteger blue = [[_ imageView subviews] indexOfObject: blueView]; NSInteger green = [[_ imageView subviews] indexOfObject: greenView]; [_ imageView exchangeSubviewAtIndex: green withSubviewAtIndex: blue]; // call a method after the animation is complete // [UIView setAnimationDidStopSelector: @ selector (animationFinished :)]; [UIView commitAnimations]; // ends an animation block and starts when it is outside the animation block}-(NSString *) getAnimationType :( NSInteger) index {NSString * type = nil; switch (index) {case 5: type = kCATransitionFade; break; case 6: type = kCATransitionPush; break; case 7: type = kCATransitionReveal; break; case 8: type = kCATransitionMoveIn; break; case 4: type = @ "cube"; break; case 3: type = @ "suckEffect"; break; case 1: type = @ "pageCurl"; break; case 2: type = @ "pageUnCurl"; break; default: break;} return type;}-(NSString *) getSubType {NSString * subtype = nil; switch (self. typeID) {case 0: subtype = kCATransitionFromLeft; break; case 1: subtype = break; case 2: subtype = kCATransitionFromRight; break; case 3: subtype = kCATransitionFromTop; break; default: break;} self. typeID + = 1; if (self. typeID> 3) {self. typeID = 0;} return subtype;}-(void) viewDidLoad {[super viewDidLoad]; [self. view setBackgroundColor: [UIColor whiteColor]; [self. navigationItem setTitle: @ "animation Effects"]; UIButton * addBtn1 = [[UIButton alloc] initWithFrame: CGRectMake (10, 70, 80, 30)]; [addBtn1 setTitle: @ "Paging" forState: UIControlStateNormal]; addBtn1.titleLabel. font = [UIFont character: 13.0f]; [addBtn1 setBackgroundColor: [UIColor grayColor]; character = 1; [addBtn1 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn1]; UIButton * addBtn2 = [[UIButton alloc] initWithFrame: CGRectMake (, 80, 30)]; [addBtn2 setTitle: @ "" forState: UIControlStateNormal]; addBtn2.titleLabel. font = [UIFont character: 13.0f]; [addBtn2 setBackgroundColor: [UIColor grayColor]; character = 2; [addBtn2 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn2]; UIButton * addBtn3 = [[UIButton alloc] initWithFrame: CGRectMake (, 80, 30)]; [addBtn3 setTitle: @ "Ripple" forState: Success]; addBtn3.titleLabel. font = [UIFont character: 13.0f]; [addBtn3 setBackgroundColor: [UIColor grayColor]; character = 3; [addBtn3 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn3]; UIButton * addBtn4 = [[UIButton alloc] initWithFrame: CGRectMake (280,70, 80, 30)]; [addBtn4 setTitle: @ "cube" forState: Unknown] addBtn4.titleLabel. font = [UIFont character: 13.0f]; [addBtn4 setBackgroundColor: [UIColor grayColor]; character = 4; [addBtn4 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn4]; UIButton * addBtn5 = [[UIButton alloc] initWithFrame: CGRectMake (10,110, 80, 30)]; [addBtn5 setTitle: @ "Fade" forState: Unknown]; addBtn5.titleLabel. font = [UIFont character: 13.0f]; [addBtn5 setBackgroundColor: [UIColor grayColor]; character = 5; [addBtn5 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn5]; UIButton * addBtn6 = [[UIButton alloc] initWithFrame: CGRectMake (100,110, 80, 30)]; [addBtn6 setTitle: @ "push" forState: Pushed]; addBtn6.titleLabel. font = [UIFont character: 13.0f]; [addBtn6 setBackgroundColor: [UIColor grayColor]; character = 6; [addBtn6 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn6]; UIButton * addBtn7 = [[UIButton alloc] initWithFrame: CGRectMake (190,110, 80, 30)]; [addBtn7 setTitle: @ "uncover" forState: Unknown]; addBtn7.titleLabel. font = [UIFont character: 13.0f]; [addBtn7 setBackgroundColor: [UIColor grayColor]; character = 7; [addBtn7 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn7]; UIButton * addBtn8 = [[UIButton alloc] initWithFrame: CGRectMake (280,110, 80, 30)]; [addBtn8 setTitle: @ "Overwrite" forState: Unknown]; addBtn8.titleLabel. font = [UIFont character: 13.0f]; [addBtn8 setBackgroundColor: [UIColor grayColor]; character = 8; [addBtn8 addTarget: self action: @ selector (animationFunction :) forControlEvents: role]; [self. view addSubview: addBtn8]; UIButton * addBtn9 = [[UIButton alloc] initWithFrame: CGRectMake (10,150, 80, 30)]; [addBtn9 setTitle: @ "flip" forState: UIControlStateNormal]; addBtn9.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn9 setBackgroundColor: [UIColor grayColor]; duration = 9; [addBtn9 addTarget: self action: @ selector (parent :) forControlEvents: role]; [self. view addSubview: addBtn9]; UIButton * addBtn10 = [[UIButton alloc] initWithFrame: CGRectMake (100,150, 80, 30)]; [addBtn10 setTitle: @ "flip down" forState: UIControlStateNormal]; addBtn10.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn10 setBackgroundColor: [UIColor grayColor]; Weight = 10; [addBtn10 addTarget: self action: @ selector (parent :) forControlEvents: role]; [self. view addSubview: addBtn10]; UIButton * addBtn11 = [[UIButton alloc] initWithFrame: CGRectMake (190,150, 80, 30)]; [addBtn11 setTitle: @ "Turn left" forState: UIControlStateNormal]; addBtn11.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn11 setBackgroundColor: [UIColor grayColor]; duration = 11; [addBtn11 addTarget: self action: @ selector (parent :) forControlEvents: role]; [self. view addSubview: addBtn11]; UIButton * addBtn12 = [[UIButton alloc] initWithFrame: CGRectMake (280,150, 80, 30)]; [addBtn12 setTitle: @ "" forState: UIControlStateNormal]; addBtn12.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn12 setBackgroundColor: [UIColor grayColor]; duration = 12; [addBtn12 addTarget: self action: @ selector (parent :) forControlEvents: role]; [self. view addSubview: addBtn12]; _ imageView = [[UIView alloc] initWithFrame: CGRectMake (0,190, [UIScreen mainScreen]. bounds. size. width, KS_HEIGTH-190)]; [self. view addSubview: _ imageView]; blueView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "XXX_123.png"]; blueView. frame = CGRectMake (0, 0, [UIScreen mainScreen]. bounds. size. width, KS_HEIGTH-150); [_ imageView addSubview: blueView]; greenView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "XXX_321.png"]; greenView. frame = CGRectMake (0, 0, [UIScreen mainScreen]. bounds. size. width, KS_HEIGTH-150); [_ imageView addSubview: greenView];}-(void) didreceivemorywarning {[super didreceivemorywarning];} @ 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.