UIWebView在方向更改时重新计算内在内容大小

时间:2015-08-05 10:54:25

标签: ios8 uiwebview autolayout screen-orientation

UIWebview在第一次以potrait模式启动时效果非常好。

但是在切换到横向模式后,即使我指定了

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
      [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];


      [self layoutsubviews];
}

请告知我如何让UIWebView重新计算其内在内容,因为它现在在横向模式下无法正确呈现

1 个答案:

答案 0 :(得分:0)

只需使用animateAlongsideTransition:completion:方法

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{   
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
    {
        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
        // do whatever
    } completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
    { 

    }];

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}