【问题标题】:HTML5's canvas + Javascript code not working on iOSHTML5 的画布 + Javascript 代码在 iOS 上不起作用
【发布时间】:2012-05-24 02:28:38
【问题描述】:

我完成了一个用于 javascript + html5 画布的基本引擎。很简陋。它适用于浏览器,但不适用于 iOS。

我是否使用了尚未在 Safari Mobile 上实现的功能,或者其他? :(

http://bluecodestudio.com/kipos/gametest.html

【问题讨论】:

    标签: javascript ios html canvas safari


    【解决方案1】:

    在keyboardJS.init() 中,您在事件回调中使用了bind() 方法。

    document.addEventListener("keydown", this.keyIsDown.bind(this));
    document.addEventListener("keyup", this.keyIsUp.bind(this));
    

    Safari(包括移动版 Safari)不支持 bind() 方法。你需要提供一个 polyfill:

    /**
    *    Bind.js
    *    Copyright 2010, WebReflection
    *    License: http://www.opensource.org/licenses/mit-license.php
    */
    if (Function.prototype.bind === null || Function.prototype.bind === undefined) {
        Function.prototype.bind = (function (slice) {
            // (C) WebReflection - Mit Style License
            function bind(context) {
                var self = this; // "trapped" function reference
                // only if there is more than an argument
                // we are interested into more complex operations
                // this will speed up common bind creation
                // avoiding useless slices over arguments
                if (1 < arguments.length) {
                    // extra arguments to send by default
                    var $arguments = slice.call(arguments, 1);
                    return function () {
                        return self.apply(
                            context,
                        // thanks @kangax for this suggestion
                            arguments.length ?
                        // concat arguments with those received
                                $arguments.concat(slice.call(arguments)) :
                        // send just arguments, no concat, no slice
                                $arguments
                        );
                    };
                }
                // optimized callback
                return function () {
                    // speed up when function is called without arguments
                    return arguments.length ? self.apply(context, arguments) : self.call(context);
                };
            }
    
            // the named function
            return bind;
    
        } (Array.prototype.slice));
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-26
      • 2012-08-10
      • 2016-06-15
      • 2020-08-29
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多