iPhone/iPad HTML5 Canvas fillText problem

99封情书 提交于 2020-01-01 03:24:10

问题


I'm having strange issues with text on a canvas when using an iPhone or iPad. Either the text gets drawn properly (rarely), or it gets drawn upside down, or it doens't get drawn at all. When the text does manage to get drawn, it is wiped when the iPhone/Pad is rotated.

I have the following code. It seems that I can only get the text to stay on the page at all if I use a setTimeout. It seems to be drawn over if I call fillText as soon as the document is loaded.

Anyone else experiencing this sort of problem?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        //draw_b();
        setTimeout('draw_b()', 500); ;
    });

    function draw_b() {
        var b_canvas = document.getElementById("cv");
        var context = b_canvas.getContext("2d");
        context.fillText("Belated hello world", 50, 50);
    }
</script>
</head>
<body>
<canvas id="cv" width="300" height="225"></canvas>

</body>
</html>

回答1:


I have the same problem , the earlier version(3.2) doesn't support HTML5 Canvas filltext, You can use alternative API such stroketext to fix this issue: http://www.netzgesta.de/dev/text/#canvas_api



来源:https://stackoverflow.com/questions/2998941/iphone-ipad-html5-canvas-filltext-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!