1

我想构建一个基于https://github.com/ECSlidingViewController/ECSlidingViewController的特殊动画。

缩放动画如下图所示。

在此处输入图像描述

我只想通过 PI / 4 旋转主视图控制器。如下图所示。

在此处输入图像描述

我曾尝试像下面的代码一样进行 EndState 转换,但它不起作用。

- (void)topViewAnchorRightEndState:(UIView *)topView anchoredFrame:(CGRect)anchoredFrame {

CATransform3D toViewRotationPerspectiveTrans = CATransform3DIdentity;
toViewRotationPerspectiveTrans.m34 = -0.003;
toViewRotationPerspectiveTrans = CATransform3DRotate(toViewRotationPerspectiveTrans, M_PI_4, 0.0f, -1.0f, 0.0f);

topView.layer.transform = toViewRotationPerspectiveTrans;
topView.layer.position = CGPointMake(anchoredFrame.origin.x + ((topView.layer.bounds.size.width * MEZoomAnimationScaleFactor) / 2), topView.layer.position.y);
}

任何帮助、指针或示例代码片段将不胜感激!

4

2 回答 2

1

我设法做到了。从 ECSlidingViewController 中给出的缩放动画代码中,不要在

- (CGRect)topViewAnchoredRightFrame:(ECSlidingViewController *)slidingViewController{
    CGRect frame = slidingViewController.view.bounds;

    frame.origin.x    = slidingViewController.anchorRightRevealAmount;
    frame.size.width  = frame.size.width/*  * MEZoomAnimationScaleFactor*/;
    frame.size.height = frame.size.height/* * MEZoomAnimationScaleFactor*/;
    frame.origin.y    = (slidingViewController.view.bounds.size.height - frame.size.height) / 2;

    return frame;
}

通过评论MEZoomAnimationScaleFactor

然后在- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext方法的顶部添加

[topView.layer setAnchorPoint:CGPointMake(0, 0.5)];
[topView.layer setZPosition:100];

最后,进行所有转换的方法必须是:

- (void)topViewAnchorRightEndState:(UIView *)topView anchoredFrame:(CGRect)anchoredFrame {
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = -0.003;
    transform = CATransform3DScale(transform, ARDXZoomAnimationScaleFactor, ARDXZoomAnimationScaleFactor, 1);
    transform = CATransform3DRotate(transform, -M_PI_4, 0.0, 1.0, 0.0);
    topView.layer.transform = transform;
    topView.frame = anchoredFrame;
    topView.layer.position  = CGPointMake(anchoredFrame.origin.x, anchoredFrame.size.height/2+anchoredFrame.origin.y);
}

享受你的动画:)

于 2014-12-26T12:24:17.167 回答
0

在 ryancrunchi 的回答之上,您还需要修改 topViewStartingState 以将 x 位置重置为 0 而不是容器框架的中间。这消除了动画开始时的抖动偏移:

改变

- (void)topViewStartingState:(UIView *)topView containerFrame:(CGRect)containerFrame {
    topView.layer.transform = CATransform3DIdentity;
    topView.layer.position  = CGPointMake(containerFrame.size.width / 2, containerFrame.size.height / 2);
}

- (void)topViewStartingState:(UIView *)topView containerFrame:(CGRect)containerFrame {
    topView.layer.transform = CATransform3DIdentity;
    topView.layer.position  = CGPointMake(0, containerFrame.size.height / 2);
}

动画中还有一个错误导致在打开动画结束时出现一个生涩的左侧菜单。从动画的完成部分复制以下行,使其在动画期间运行:

[self topViewAnchorRightEndState:topView anchoredFrame:[transitionContext finalFrameForViewController:topViewController]];

动画函数现在看起来像:

...
if (self.operation == ECSlidingViewControllerOperationAnchorRight) {
        [containerView insertSubview:underLeftViewController.view belowSubview:topView];
        [topView.layer setAnchorPoint:CGPointMake(0, 0.5)];

        [topView.layer setZPosition:100];

        [self topViewStartingState:topView containerFrame:containerView.bounds];
        [self underLeftViewStartingState:underLeftViewController.view containerFrame:containerView.bounds];

        NSTimeInterval duration = [self transitionDuration:transitionContext];
        [UIView animateWithDuration:duration animations:^{
            [self underLeftViewEndState:underLeftViewController.view];
            underLeftViewController.view.frame = [transitionContext finalFrameForViewController:underLeftViewController];
            [self topViewAnchorRightEndState:topView anchoredFrame:[transitionContext finalFrameForViewController:topViewController]];
        } completion:^(BOOL finished) {
            if ([transitionContext transitionWasCancelled]) {
                underLeftViewController.view.frame = [transitionContext finalFrameForViewController:underLeftViewController];
                underLeftViewController.view.alpha = 1;
                [self topViewStartingState:topView containerFrame:containerView.bounds];
            }

            [transitionContext completeTransition:finished];
        }];
    }
... 
于 2015-02-16T02:38:18.690 回答