gpt4 book ai didi

objective-c - CATransition 是如何工作的?

转载 作者:行者123 更新时间:2023-12-02 07:46:01 36 4
gpt4 key购买 nike

我有两个 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 动画 block 的原因?这是自 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/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com