在animateTransition期间,如何在ToViewController中获取子视图的框架? [英] How do I get the frame of a subview in the ToViewController during animateTransition:?

查看:58
本文介绍了在animateTransition期间,如何在ToViewController中获取子视图的框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 7引入的新的自定义过渡,并且试图将视图从主"视图控制器移动到详细"视图控制器中的视图,就像Photos.app放大时一样轻按照片时,该照片除外,详细信息vc中的该视图仅占据屏幕的一半.为此,我试图通过从局部或toViewController中获取最终帧来使该视图动画化为最终帧.但是,我得到的帧是从Interface Builder到toViewController的视图的起始帧,而不是在AutoLayer对其进行传递之后出现的视图.通过自动版面设置设置框架后,如何获得框架?我已经在toViewController特殊视图框架返回到animateTransition之前尝试过[self.view layoutSubviews]:但这仍然提供了IB布局.

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]];

    }];

}

推荐答案

调用layoutIfNeeded而不是layoutSubviews,以强制进行布局传递.然后应该更新框架.

Call layoutIfNeeded, not layoutSubviews, to force a layout pass. Then the frame should be updated.

这篇关于在animateTransition期间,如何在ToViewController中获取子视图的框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆