我使用iOS 7引入的新自定义过渡,我试图将视图从“主”视图控制器移动到我的“详细信息”视图控制器中的视图,类似于Photos.app放大的方式点击它时的照片,除了详细视图中的此视图仅占用屏幕的一半。要做到这一点,我试图通过从细节或toViewController获取最终帧来将此视图设置为最终帧的动画。然而,我得到的框架是来自Interface Builder的toViewController视图的起始框架,而不是AutoLayer在其上传递后出现的视图。如何通过自动布局设置框架后获取框架?我在toViewController特殊视图框架返回animateTransition之前尝试了[self.view layoutSubviews]:但仍然给出了IB布局。
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.alpha = 0;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.alpha = 0;
toViewController.view.alpha = 1;
fromViewController.specialView = [toViewController detailSpecialViewFrame];
} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
答案 0 :(得分:0)
调用layoutIfNeeded而不是layoutSubviews来强制布局传递。然后应该更新框架。