2015-03-02 44 views
0

我有一个自定义的视图控制器之间的过渡动​​画,并且我想要一个UILabel(或出现)在fromViewController和toViewController上都是相同的。如何在iOS8的自定义过渡动画中“传递”持久性标签?

我试过如下:

toViewController.nameLabel = fromViewController.nameLabel; 

在下面的代码的情况下却得到了以下错误:

[UINavigationController nameLabel]: unrecognized selector sent to instance

我在做什么错?

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext { 
    // Grab the from and to view controllers from the context 
    HC_ExercisePageVC *fromViewController = (HC_ExercisePageVC *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    HC_TimerVC *toViewController = (HC_TimerVC *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    if (self.presenting) { 

     fromViewController.view.userInteractionEnabled = NO; 

     [transitionContext.containerView addSubview:toViewController.view]; 

     CGRect startFrame = endFrame; 
     startFrame.origin.y += 75; 
     toViewController.movingViews.frame = startFrame; 

     toViewController.nameLabel = fromViewController.nameLabel; 

     [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
      toViewController.movingViews.frame = endFrame; 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:YES]; 
     }]; 
    } 
    else { 

更新:继@Gavin的建议,我取代了代码:

// Grab the from and to view controllers from the context 
HC_ExercisePageVC *fromViewController = (HC_ExercisePageVC *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
UINavigationController *toViewControllerNavigation = (id)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
HC_TimerVC * toViewController = (HC_TimerVC *)toViewControllerNavigation.viewControllers.firstObject; 

但是,当我这样做,我得到错误:

-[HC_TimerVC viewControllers]: unrecognized selector sent to instance

我总是挂上如何处理navcontrollers ...

回答

0

看起来像你的toViewController包含在UINavigationController内,因此它将返回作为目的地。

所以你需要从导航控制器抢HC_TimerVC

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext { 
    // Grab the from and to view controllers from the context 
    HC_ExercisePageVC *fromViewController = (HC_ExercisePageVC *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UINavigationController *toViewControllerNavigation = (id)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
    HC_TimerVC * toViewController = toViewControllerNavigation.viewControllers.firstObject; 
    .... 
相关问题