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 ...