问题
I an using the new custom transitions introduced with iOS 7 and I'm trying to move a view from my 'master' view controller to a view in my 'detail' view controller kind of like how Photos.app zooms in on a photo when you tap on it except this view in the detail vc only takes up half of the screen. To do this I'm trying to animate this view to it's final frame by getting the final frame from the detail or toViewController. However the frame I get is the starting frame from Interface Builder for the toViewController's view and not the view that appears after AutoLayer has taken a pass at it. How do I get the frame after it has been set by Auto Layout? I have tried [self.view layoutSubviews] right before the toViewController special view frame is returned to animateTransition: but that still gives the IB layout.
- (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]];
}];
}
回答1:
Call layoutIfNeeded, not layoutSubviews, to force a layout pass. Then the frame should be updated.
来源:https://stackoverflow.com/questions/25506785/how-do-i-get-the-frame-of-a-subview-in-the-toviewcontroller-during-animatetransi