Animation in iOS (1)-UIView Animation

Source: Internet
Author: User

UIView animation in iOS

ViewController1.h

#import 
 
  @interface ViewController1 : UIViewController@property(nonatomic,retain)UIView* view1;@end
 
ViewController1.m



# Import "ViewController1.h" @ interface ViewController1 () @ end @ implementation ViewController1-(id) initWithNibName :( NSString *) bundle :( NSBundle *) {{ self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. _ view1 = [[UIView alloc] init]; _ view1.frame = CGRectMake (0, 44,160,200); _ view1.backgroundColor = [UIColor redColor]; [self. view addSubview: _ view1]; // The effect of over-animation. It is the result of switching UIButton * button2 = [[UIButton alloc] initWithFrame: CGRectMake (20,340,150, 30)] for two views. [button2 addTarget: self action: @ selector (button2) forControlEvents: Events]; [button2 setTitle: @ "Start Animation" forState: UIControlStateNormal]; button2.backgroundColor = [UIColor redColor]; [self. view addSubview: button2];}-(void) button2 {// 1 traditional method // start animation/* [UIView beginAnimations: @ "testanimation" context: nil]; [UIView setAnimationDuration: 0.5]; // The animation proxy [UIView setAnimationDelegate: self]; // The animation RESPONSE event so that the view automatically returns to the original position [UIView setAnimationDidStopSelector: @ selector (animationstop)]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; // obtain the view position CGRect frames = self. view1.frame; // move the coordinates to frames at 160 on the right. origin. x = 160; self. view1.frame = frames; [UIView commitAnimations]; * // 2 implement [UIView animateWithDuration: 0.5 animations: ^ {CGRect frames = self. view1.frame; frames. origin. x = 160; self. view1.frame = frames; // scale self. view1.transform = CGAffineTransformScale (self. view1.transform, 0.01, 0.01);} completion: ^ (BOOL finished) {CGRect frames = self. view1.frame; frames. origin. x = 0; self. view1.frame = frames; // restore to the original zooming self. view1.transform = transition;}];}-(void) animationstop {// traditional method [UIView beginAnimations: nil context: nil]; [UIView setAnimationDuration: 0.5]; CGRect frames = self. view1.frame; frames. origin. x = 0; self. view1.frame = frames; [UIView commitAnimations];}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end



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.