iOS Transition动画

时间:2016-02-23 09:34:38

标签: ios animation

我试图创建一个透明的模态弹出式动画,我开始工作,除非我旋转视图时,它保持相同的大小。有人能指出我正确的方向吗?以下是我目前使用的动画代码

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    UIView *inView = [transitionContext containerView];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    [inView addSubview:toVC.view];

    CGRect screenRect = fromVC.view.bounds;
    [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];

    [UIView animateWithDuration:0.25f
        animations:^{

          [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];
        }
        completion:^(BOOL finished) {
          [transitionContext completeTransition:YES];
        }];
}

1 个答案:

答案 0 :(得分:0)

我只是尝试使用组合自动布局的代码,视图调整大小适合我。只是为了确保,这是你想要实现的目标吗?

enter image description here

修改 以下是我实施此步骤的步骤

  1. 将segue添加到情节提要中的视图控制器 enter image description here
  2. 创建过渡类(比如MyTransitionClass)。
  3. 将UIViewControllerTransitioningDelegate添加到父视图控制器
  4. 在父视图控制器中实现animationControllerForPresentedController方法,如此

    -(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return [[MyTransitionClass alloc] init];
    }