2

我想知道是否可以在自定义 Segue 转换中使用 CATransition。我创建了我的 CustomSegueTransition.m 文件并在我希望发生转换的自定义 segue 类中引用它。

这是我的 CustomSegueTransition.m 文件的代码:

#import "CustomSegueTransition.h"
#import "QuartzCore/QuartzCore.h"

@implementation CustomSegueTransition

-(void) perform {

    // set up an animation for the transition the content
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.25];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25];

    [UIView commitAnimations];
}

@end

它没有给我任何错误警告,但是当按下按钮导致转场转换时,转换不会执行。我是否遗漏了 CATransition 代码中的某些内容,或者这不可能?

谢谢!

4

4 回答 4

1

@Grant

I don't have complete answer for you, but I did notice that you never call a new view thus there is no transition. I don't know whether you are shooting for a push, pop, or modal but here is the type of code you will need to add:

UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;   
[src presentModalViewController:dst animated:YES];

or

    [src presentViewController:<#(UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>];

I believe there are other problems with setting up the custom animation which I don't have an answer for though I am interested in the solution.

于 2011-12-18T18:54:41.257 回答
0

这是有效的完整代码

-(void)perform {

__block UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
__block UIViewController *destinationController = (UIViewController*)[self destinationViewController];                    

CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom  

[sourceViewController.navigationController.view.layer addAnimation:transition
                                            forKey:kCATransition];

[sourceViewController.navigationController pushViewController:destinationController animated:NO];

 }
于 2012-06-28T10:05:04.133 回答
0

不知道你在尝试什么,但我确实发现了一个问题。

您创建了一个过渡动画,但从未使用过它。您需要在要设置动画的视图层上添加动画。

此外,如果您要使用较低级别的 CoreAnimation 功能,则不需要使用 [UIView beginAnimation]...[UIView commitAnimation]。

如果需要,请使用 [CATransaction begin]...[CATransaction commit]。

于 2011-12-18T20:46:16.327 回答
0

导入 QuartzCore 框架。

- (void)pushViewWithCustomTranstion {
    CATransition* transition = [CATransition animation];
    transition.duration = 0.4f;
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromRight;
    [self.navigationController.view.layer addAnimation:transition
                                                forKey:kCATransition];
    YourDestinataionController *yourVC = [[YourDestinataionController alloc] init];
    [self.navigationController pushViewController:yourVC animated:NO];
}

将您的视图控制器推送到具有自定义过渡效果的导航控制器中是简单和最简单的代码。

于 2015-09-04T13:15:53.510 回答