开发者

how does the CATransition work?

i have two views,one is aV开发者_StackOverflowiew,another is bView, there is a button on aView,i click the button ,i will jump to bView,please see the code

-(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"];
 }

it can not work well,it can jump,so what can i do?thanks


You forgot to actually add the view at the end...

-(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];
}

Is there reason why you're not using UIView animation blocks? It's the recommended method for animations since iOS 4. Using UIView's transitionFromView:toView:duration:options:completion: should work for you...

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

I used UIViewAnimationOptionTransitionCurlUp as an example for the transition option, but you can choose any UIViewAnimationOption.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜