两个UIViews之间的动画

时间:2012-02-25 07:17:35

标签: ios

    view=[[UIView alloc]init];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:2];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                       forView:self.view cache:YES];
[self.view addSubview:view.view];
    [UIView commitAnimations];

我使用这个但我想要两个导航控制器之类的动画。 我正在使用两个UIViews。

1 个答案:

答案 0 :(得分:6)

您需要将过渡动画应用于包含从一个子视图转换到另一个子视图的动画的父视图。

UIView* view=[[UIView alloc]init];
UIView* parentView = self.view.superview;
[self.view removeFromSuperView];
[parentView addSubview:view];


CATransition *animation = [CATransition animation];
[animation setDelegate:self]; // set your delegate her to know when transition ended

[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight]; // set direction as you need

[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[parentView layer] addAnimation:animation forKey:@"viewPush"];

您可能需要进一步调整此代码以适应您的课堂设计等情况。