0

に数式を表示するために mathjax を使用していUIWebViewます。UIWebViewだから私は高さを動的に変更したい。そのために、私は使用しました

CGFloat newHeight = [[self.questionWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight;"] floatValue];

webViewDidFinishLoad:デリゲートメソッドで。

ここで私の問題は、正規表現を使用している場合、UIWebView高さが次の画像のように正しい値を返すことです。

ここに画像の説明を入力

/,(,)を含む式を入力すると、次の画像のように間違った高さが得られます

ここに画像の説明を入力

 NSString *html = [NSString stringWithFormat:@"<html><head><title>Untitled</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /><script type=\"text/x-mathjax-config\">MathJax.Hub.Config({extensions: [\"tex2jax.js\"],jax: [\"input/TeX\",\"output/HTML-CSS\"],tex2jax: {inlineMath: [[\"$\",\"$\"],[\"\\(\",\"\\)\"]]}});</script><script type=\"text/javascript\" src=\"../MathJax.js?config=AM_HTMLorMML-full\"></script></head><style>.Question {font-family:'Times New Roman',arial;font-weight:normal;font-size:12px;color:#323232;}</style><body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"Question\" align=\"left\" width=\"260\" height=\"40\"><tr><td> `x + 3 = 2` </td></tr></div></body></html>"];

[self writeStringToFile:tempDir fileName:@"test1.html" pathName:filePath content:html];

NSURLRequest* req = [[NSURLRequest alloc] initWithURL:url];

[self.myWebView loadRequest:req]; 

writeStringToFile:メソッドでは、

-(void)writeStringToFile:(NSString *)dir fileName:(NSString *)strFileName pathName:(NSString *)strPath content:(NSString *)strContent{

    NSString *path = [dir stringByAppendingPathComponent:strFileName];
    NSString *foo0 = @"<html><head><meta name='viewport' content='initial-scale=1.0;maximum-scale=100.0;user-scalable=1'/>"
    "<script type='text/javascript' src='";
    NSString *foo1 = @"?config=AM_HTMLorMML-full'></script>"
    "</head>"
    "<body>";
    NSString *foo2 = @"</body></html>";
    NSString *fooFinal = [NSString stringWithFormat:@"%@%@%@%@%@",foo0,strPath,foo1,strContent,foo2];

    [fooFinal writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
}

正確な高さを取得するには?

前もって感謝します!

4

3 に答える 3