Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

objective c - how does the CATransition work?

i have two views,one is aView,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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...