Reputation: 1595
I have add a view animation to my view on button click, the view will slide to right side on first click and will come back on second click..(just like in Facebook iPhone app)
But the animation is not so smooth, there are some jerkings and all. But when it reaches the final (x, y) they are in correct position, when the view is moving the animation doesn't look so professional.Help me to correct this
and one question,is there any way to animate the below tabbar with the same event. (You can see in images that the tabbar is not moved with animation)
Adding the code here!
- (IBAction)ShowView:(id)sender
{
if (n==0)
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.view.center = CGPointMake(410, 205);
[[self.view layer] addAnimation:animation forKey:@"SwitchToNoti"];
n=1;
}else
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.view.center = CGPointMake(160,205);
[[self.view layer] addAnimation:animation forKey:@"SwitchTohome"];
n=0;
}
Upvotes: 0
Views: 677
Reputation: 293
try this
- (IBAction)ShowView:(id)sender {
if (n==0)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view setCenter:CGPointMake(self.view.center.x + 100, self.view.center.y)];
[UIView commitAnimations];
n=1;
}else
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view setCenter:CGPointMake(self.view.center.x - 100, self.view.center.y)];
[UIView commitAnimations];
n=0;
}
}
Upvotes: 1
Reputation: 229
You can use the following code to show the animation :-
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.view.frame = TestRect;
[UIView commitAnimations];
You need to make a CGRect named TestRect here and see if this solves your problem.
Upvotes: 0