CATransition如何运作?

时间:2011-08-07 16:17:33

标签: objective-c catransition

我有两个视图,一个是aView,另一个是bView,aView上有一个按钮,我点击按钮,我会跳转到bView,请看代码

-(IBAction)jump2b:(id)sender{
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.25f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
   [bView.view.layer addAnimation:animation forKey:@"animation"];
 }

它不能很好地工作,它可以跳,所以我能做什么?谢谢

1 个答案:

答案 0 :(得分:7)

你忘了在最后添加视图......

-(IBAction)jump2b:(id)sender{
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.25f;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromTop;
    [bView.view.layer addAnimation:animation forKey:@"animation"];

    //add bView to current view
    [self.view addSubview:bView];
}

你有没有理由不使用UIView动画块?这是iOS 4以来动画的推荐方法。使用UIView的transitionFromView:toView:duration:options:completion:应该适合你...

[UIView transitionFromView:aView 
                    toView:bView 
                  duration:0.25 
                   options: (UIViewAnimationCurveEaseInOut | UIViewAnimationOptionTransitionCurlUp)
                completion:nil];

我使用UIViewAnimationOptionTransitionCurlUp作为转换选项的示例,但您可以选择任何UIViewAnimationOption。