首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CATransition不工作

CATransition不工作
EN

Stack Overflow用户
提问于 2013-04-24 09:17:21
回答 2查看 681关注 0票数 0

我想使一个自定义的波纹transition.The过渡工作,但没有波纹effect.Here是我的代码

代码语言:javascript
复制
    - (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];


}
EN

回答 2

Stack Overflow用户

发布于 2013-04-24 09:43:53

rippleEffect是一种没有文档记录的动画类型,您不能依赖它在任何特定的iOS版本之间(或者根本不能)像这里讨论的那样工作:ripple effect animation。我强烈建议你自己实现这个动画,或者找一个替代方案。

票数 1
EN

Stack Overflow用户

发布于 2013-04-24 11:01:58

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

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

代码语言:javascript
复制
 - (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];
            }
        }];
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16181799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档