Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate the view Left to Right in iPhone?

How to animate the view transition left to right(Similar push view). When i click the button, the view should be transited from left to right. So please guide me and give some sample links.

Thanks.

like image 642
Pugalmuni Avatar asked Dec 08 '10 12:12

Pugalmuni


1 Answers

Suppose that you want to push view2 from the right to replace view1.

// Set up view2
view2.frame = view1.frame;
view2.center = CGPointMake(view1.center.x + CGRectGetWidth(view1.frame), view1.center.y);
[view1.superview addSubview: view2];
// Animate the push
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)];
view2.center = view1.center;
view1.center = CGPointMake(view1.center.x - CGRectGetWidth(view1.frame), view1.center.y);
[UIView commitAnimations];

Then (optionally) implement this method to remove view1 from the view hierarchy:

- (void) pushAnimationDidStop: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context {
    [view1 removeFromSuperview];
}

In that animation delegate method you may also want to release view1 and set its reference to nil, depending on whether you need to keep it around after the transition.

like image 170
Costique Avatar answered Oct 03 '22 06:10

Costique