简体   繁体   English

Canvas SignaturePad在Mobile Phonegap App(Android)上未清除

[英]Canvas SignaturePad doesn't clear on Mobile Phonegap App (Android)

Our application has the feature of drawing a signature on a pad. 我们的应用程序具有在书写板上绘制签名的功能。 We're using the signature pad created by szimek and also make use of Ionic AngularJS framework. 我们使用的是szimek创建的签名板,还使用了Ionic AngularJS框架。

Usecase Description 用例说明

The person clicks on a button and the system opens a Modal screen which then shows the signature pad. 该人员单击一个按钮,系统将打开“模态”屏幕,然后显示签名板。 The user can clear and save the image. 用户可以清除并保存图像。 When he saves it and opens the signature pad again (by pressing on the button) the previous drawn image is displayed and the user can add something to it. 当他保存它并再次打开签名板时(通过按下按钮),将显示先前绘制的图像,并且用户可以向其中添加一些内容。

在此处输入图片说明

The Problem 问题

The problem we're encountering is that on the Android device. 我们遇到的问题是Android设备上的问题。 When the user has drawn an image and returns to the signature view, it displays the previous drawn image but it doesn't dissapear when the person clears it. 当用户绘制图像并返回到签名视图时,它会显示先前绘制的图像,但是当该人清除图像时它不会消失。 It does 'clears' it because after saving it, it saves an empty image. 它会“清除”它,因为保存后会保存一个空图像。 It's almost like it shows a cached image. 就像显示缓存的图像一样。 We want to screen to be clear of any images after pressing the 'clear'-button. 按下“清除”按钮后,我们希望屏幕上没有任何图像。

There is something in the progress of wiping the canvas in which the Android doesn't do correctly. 在擦拭画布的过程中,Android无法正常工作。 In each other tested device (IPad, Browser on the desktop) it appears to work fine. 在其他每台经过测试的设备(iPad,台式机上的浏览器)中,它似乎都可以正常工作。

Code

Modal opening 模态开口

It all begins in the orderView.html. 一切都始于orderView.html。 There I assign a click event to open a modal screen with the signature pad: 在那里,我分配了一个click事件,以使用签名板打开模式屏幕:

<ion-item ng-click="openModal('app/components/order/signature/signaturepadView.html', $event)">
                    <div class="signature padding" ng-switch="_signatureImage || '_undefined_'">
                        <img ng-switch-when="_undefined_" ng-src="assets/img/signature_placeholder.png" alt="" />
                        <img ng-switch-default ng-src="{{_signatureImage}}" alt="" />
                    </div>
                </ion-item>

Ionic modal code: 离子模态代码:

// Ionic Modal
    $ionicModal.fromTemplateUrl('modal', {
        scope: $scope,
        animation: 'slide-in-up'
    }).then(function (modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function (include, $event) {
        $event.stopPropagation();
        $scope.include = include;
        $scope.modal.show();
    };
    $scope.closeModal = function () {
        $scope.modal.hide();
        $scope._signatureImage = OrderService.getSignatureImage();
    };

    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function () {
        $scope.modal.remove();
    });

signatureView.html signatureView.html

This is the code in the signatureView.html file. 这是signatureView.html文件中的代码。

<ion-modal-view class="modal" ng-controller="SignatureCtrl">
    <ion-pane>
        <ion-header-bar class='bar-stable'>
            <h1 class='title'> Signature </h1>
            <ion-header-buttons side="left">
                <button class="button signature-back-button" ng-click="closeModal()"><i class="icon ion-ios-arrow-back"></i> Back</button>     
            </ion-header-buttons>
        </ion-header-bar>
        <ion-content class='has-header' scroll='false'>
            <canvas id='signatureCanvas'></canvas>
            <div class='button-bar'>
                <a class='button button-positive' ng-click='clearCanvas()'>Clear</a>
                <a class='button button-balanced' ng-click='saveCanvas(); closeModal()'>Save</a>
            </div>
            <br>
        </ion-content>
    </ion-pane>
</ion-modal-view>

signatureController.js signatureController.js

The function are being handled in the signatureController.js: 该函数在signatureController.js中处理:

angular.module('directory.signatureController', [])

    .controller('SignatureCtrl', function ($scope, OrderService) {
        var canvas = document.getElementById('signatureCanvas');
        resizeCanvas();
        var signaturePad = new SignaturePad(canvas);
        signaturePad.backgroundColor = "white";

        signaturePad.minWidth = 2;
        signaturePad.maxWidth = 4.5;

        $scope.clearCanvas = function () {
            signaturePad.clear();
        }

        $scope.saveCanvas = function () {
            var sigImg = signaturePad.toDataURL();
            $scope.signature = sigImg;
            OrderService.setSignatureImage(sigImg);
        }

        function resizeCanvas() {
            var ratio = window.devicePixelRatio || 1;
            canvas.width = window.innerWidth; //document.width is obsolete
            canvas.height = window.innerHeight - 96; //document.height is obsolete
        };
    });

signature_pad.js signature_pad.js

From here I would suggest looking for the code in the signature_pad.js. 从这里开始,我建议您在signature_pad.js中查找代码。 I think the problem is in the clear function so I can link to the clear function in the signature file. 我认为问题出在清除函数中,因此我可以链接到签名文件中的清除函数。 For the full code here a link to his github. 有关完整的代码,请参见指向他的github的链接。

SignaturePad.prototype.clear = function () {
    var ctx = this._ctx,
        canvas = this._canvas;

    ctx.fillStyle = this.backgroundColor;
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    this._reset();
}; 

Help 救命

Please help us, if the formatting of this question is too vague or needs some elaboration, please tell me and i'll edit it. 如果此问题的格式过于模糊或需要详细说明,请帮助我们,请告诉我,我将对其进行编辑。

In all previous test the 在所有先前的测试中

signaturePad.backgroundColor = "white";

Was not needed. 不需要。 We added it and didn't test after that if this was the solution. 我们添加了它,之后没有测试这是否是解决方案。 After a brief test this morning setting the SignaturePad background color seems to fix this. 经过今天早上的简短测试后,设置SignaturePad背景色似乎可以解决此问题。

So the answer to our problem was already in our code. 因此,我们的问题的答案已经在我们的代码中。 Consider this question therefore solved. 考虑一下这个问题就解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM