【发布时间】: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