【问题标题】:How can I "pass" a persistent label in a custom transition animation in iOS8?如何在 iOS8 的自定义过渡动画中“传递”持久标签?
【发布时间】:2015-03-02 23:03:04
【问题描述】:

我在视图控制器之间有一个自定义过渡动画,我希望 UILabel 在 fromViewController 和 toViewController 上都(或出现)相同。

我尝试了以下方法:

toViewController.nameLabel = fromViewController.nameLabel;

在以下代码的上下文中,但得到以下错误:

[UINavigationController nameLabel]:无法识别的选择器发送到 实例

我做错了什么?

- (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]:无法识别的选择器发送到实例

我总是纠结于如何处理导航控制器...

【问题讨论】:

    标签: uiviewcontroller ios8 transitions


    【解决方案1】:

    看起来您的 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;
        ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-04
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-03
      相关资源
      最近更新 更多