我有两个 View ,一个是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"];
}
它不能很好地工作,它会跳,所以我该怎么办?
最佳答案
您忘了实际上在最后添加 View ...
-(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。
关于objective-c - CATransition如何运作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6973983/