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