在iOS中旋转后的UIWebview文档高度

时间:2013-12-09 12:38:30

标签: ios uiwebview height document

我有一个UIWebView,我在webViewDidFinishLoad事件中得到文档高度,如下所示:

-(void)webViewDidFinishLoad:(UIWebView *)aWebView {

    heightWebView = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
    NSLog(@"webview height: %f", heightWebView);

}

didRotateFromInterfaceOrientation事件中,我正在重新加载webView html字符串。我不知道为什么在横向和纵向模式下获得相同的文档高度。

任何解决方案?

1 个答案:

答案 0 :(得分:0)

您需要更改纵向和横向的框架。

借助 CGRectMake 方法

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    [_ScrollView setContentSize:CGSizeMake(320, 470)];
    if(toInterfaceOrientation == UIDeviceOrientationPortrait){
        [_btnBooks setFrame:CGRectMake(116, 29, 86, 88)];
    }
    else
    {
        if (IPHONE5) {
            [_btnBooks setFrame:CGRectMake(240, 29, 86, 88)];
        }
        else
        {

            [_btnBooks setFrame:CGRectMake(196, 29, 86, 88)];
        }
    }
}