iPhone Development:Animate a view in Iphone SDK

UIView Animation IOS

Tags: #UIView  #Animation #Tutorial #IOS #UIView Animation Blocks

Animation, one thing that make iPhone a cool device. So get ready to make your apps  as a cool  app through use of  animation.
Suppose you want a view to slide in from right side of screen and went toward left side.For that purpose we can use UIViewAnimation provided in IOS.
Step1: First add your view as subview
[self.view addSubview:bGView];
 
Step 2:get height of device screen area
CGRect screenFrame = [[UIScreen mainScreen] bounds];
 
Step3: give view  a frame outside the visible screen area
bGView.frame = CGRectMake(420,0,320,screenFrame.size.height);
 
Step 4:Add animation code as shown below code snippet, to bring subview/view to center of screen
[UIView animateWithDuration:2.0
        animations:^{ 
          bGView.frame = CGRectMake(0,0,320,screenFrame.size.height);
           } 
           completion:^(BOOL finished){
                    ;
                }];

Step 5: To move  View out of screen toward left hand side use given below code snippet
[UIView animateWithDuration:2.0
        animations:^{ 
          bGView.frame = CGRectMake(-420,0,320,screenFrame.size.height);
          } 
          completion:^(BOOL finished){
                    ;
                }];