2016-02-23 175 views
0

我想创建一个透明的模态弹出式动画,除了当我旋转视图时,我得到了工作,它保持相同的大小。有人能指出我正确的方向吗?以下是我目前正在使用的动画代码iOS过渡动画

- (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]; 
     }]; 
} 

回答

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]; 
    } 
    
+0

是的,而且我想你的白是透明的,并显示绿色。我只是不明白为什么它不会旋转我只是在loadView中设置视图: – Haagenti

+0

也许我在演示文稿中使用了错误的代码?那么你如何展示它?使用自定义转换? – Haagenti

+0

您使用iOS 8中定义的UIModalPresentationPopover。我使用自定义,因为我必须支持iOS 7。 – Haagenti