0

I want to make a custom segue with ripple transition.The transition works,but no ripple effect.Here is my code

    - (void)perform
{
    // Add your own animation code here.

    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.7;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.type = @"rippleEffect";

    [[[[self sourceViewController] view] layer] addAnimation:animation forKey:@"animation"];

    [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO];


}
4

2 回答 2

1

rippleEffect是一种未记录的动画类型,你不能依赖它在任何特定的 iOS 版本之间工作相同(或根本),如此处讨论的:涟漪效果动画。我强烈建议您自己实现动画或寻找替代方案。

于 2013-04-24T01:43:52.737 回答
0

这是一个可以附加到 UIViewController 的类别方法,以使用 CAAnimations 在父视图容器中的子视图之间进行转换。您可能需要根据您的目的对其进行修改,但它显示了 CATransitions 如何正确用于动画。

我写这个是为了在父 UIViewController 中创建一个来回分页效果,以便在子视图之间滑动。

 - (void) transitionFromView:(UIView*)fromView
                     toView:(UIView*)toView
         usingContainerView:(UIView*)container
              andTransition:(NSString*)transitionType{

    __block CGPoint targetOffset = fromView.center;
    __block BOOL transitionFromSameView = [toView isEqual:fromView];

    // In some cases, we want to perform the illusion of a transition when we are really just changing data in the same view.
    // In those cases, we don't need to perform this position modification.
    __block CGPoint centerOffset  = fromView.center;

    __block BOOL useAnimatedTransition = (transitionType != nil)?YES:NO;
    __block BOOL isLeftToRight = ([transitionType isEqualToString:kCATransitionFromRight])?YES:NO;

    if(transitionFromSameView == NO){
        CGFloat horizontalOffset = (isLeftToRight == YES)?[toView sizeWidth] + 100:-([toView sizeWidth] + 100);
        centerOffset = CGPointMake(fromView.center.x + horizontalOffset, fromView.center.y);
        [toView setCenter:centerOffset];
        [container insertSubview:toView belowSubview:fromView];
    }
    UIView *blockToView = toView;
    UIView *blockFromView = fromView;
    UIView *blockContainerView = container;

    if(useAnimatedTransition == NO){
        if(transitionFromSameView == NO){
            [blockToView setCenter:targetOffset];
            [blockFromView setCenter:centerOffset];
            [blockFromView removeFromSuperview];
        }  else {
            [blockToView setCenter:targetOffset];
            [blockFromView setCenter:centerOffset];
        }
    } else {

        [UIView animateWithDuration:kTransitionTime animations:^{

            CATransition *animation = [CATransition animation];
            [animation setDuration:kTransitionTime];
            [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
            [animation setType:kCATransitionMoveIn];
            [animation setSubtype:transitionType];
            [[blockContainerView layer] addAnimation:animation forKey:@"TransitionViews"];
            if(transitionFromSameView == NO){
                [blockToView setCenter:targetOffset];
                [blockFromView setCenter:centerOffset];
            }
        } completion:^(BOOL finished) {
            if(transitionFromSameView == NO){
                [blockFromView removeFromSuperview];
            }
        }];
    }
}
于 2013-04-24T03:01:57.883 回答