Android上的Phonegap平滑滚动

时间:2015-07-17 10:33:29

标签: android cordova scroll

我们能以某种方式在Android上滚动更流畅吗? 它在iPad和iPhone上运行良好,但是任何,即使是最强大的Android设备,它也不是平稳,慢下来的。我使用版本cli-5.1.1和插件人行横道。当有一张照片时,这一点尤为明显,因为你滚动它们有点抽搐。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

请参阅此网址:https://quickleft.com/blog/4-steps-to-minimizing-rendering-issues-in-cordova-applications/

您应该将以下样式应用于滚动元素:

import UIKit

class ViewController: UIViewController {

    private let kKeychainItemName = "Google Apps Script Execution API"
    private let kClientID = "493692471278-3mf6bo212flgjopl06hrjfeepphe70h4.apps.googleusercontent.com"
    private let kScriptId = "Mj0RNm2ZtohFurieBLPwnxYAb4Jnnku4P"
    // If modifying these scopes, delete your previously saved credentials by
    // resetting the iOS simulator or uninstall the app.
    private let scopes = ["https://www.googleapis.com/auth/drive"]

    private let service = GTLService() // error Use of unresolved identifier 'GTLService'


    let output = UITextView()

    // When the view loads, create necessary subviews
    // and initialize the Google Apps Script Execution API service
    override func viewDidLoad() {
        super.viewDidLoad()

        output.frame = view.bounds
        output.editable = false
        output.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
        output.autoresizingMask = UIViewAutoresizing.FlexibleHeight |
            UIViewAutoresizing.FlexibleWidth
       // error***  Binary operator '|' cannot be applied to two 'UIViewAutoresizing'      operands


        view.addSubview(output);
        // Error**Use of unresolved identifier 'GTMOAuth2ViewControllerTouch'
        if let auth = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(
            kKeychainItemName,
            clientID: kClientID,
            clientSecret: nil) {
                service.authorizer = auth
        }

    }

    // When the view appears, ensure that the Google Apps Script Execution API service is authorized
    // and perform API calls
    override func viewDidAppear(animated: Bool) {
        if let authorizer = service.authorizer,
            canAuth = authorizer.canAuthorize where canAuth {
                callAppsScript()
        } else {
            presentViewController(
                createAuthController(),
                animated: true,
                completion: nil
            )
        }
    }

    // Calls an Apps Script function to list the folders in the user's
    // root Drive folder.
    func callAppsScript() {
        output.text = "Getting folders..."
        let baseUrl = "https://script.googleapis.com/v1/scripts/\(kScriptId):run"
        let url = GTLUtilities.URLWithString(baseUrl, queryParameters: nil)
        // error ** Use of unresolved identifier 'GTLUtilities'
        // Create an execution request object.
        var request = GTLObject()   
      // Error** Use of unresolved identifier 'GTLObject'

        request.setJSONValue("getFoldersUnderRoot", forKey: "function")

        // Make the API request.
        service.fetchObjectByInsertingObject(request,
            forURL: url,
            delegate: self,
            didFinishSelector: "displayResultWithTicket:finishedWithObject:error:")
    }

    // Displays the retrieved folders returned by the Apps Script function.
    func displayResultWithTicket(ticket: GTLServiceTicket,
        finishedWithObject object : GTLObject,
        error : NSError?) {
            if let error = error {
                // The API encountered a problem before the script
                // started executing.
                showAlert("The API returned the error: ",
                    message: error.localizedDescription)
                return
            }

            if let apiError = object.JSON["error"] as? [String: AnyObject] {
                // The API executed, but the script returned an error.

                // Extract the first (and only) set of error details and cast as
                // a Dictionary. The values of this Dictionary are the script's
                // 'errorMessage' and 'errorType', and an array of stack trace
                // elements (which also need to be cast as Dictionaries).
                let details = apiError["details"] as! [[String: AnyObject]]
                var errMessage = String(
                    format:"Script error message: %@\n",
                    details[0]["errorMessage"] as! String)

                if let stacktrace =
                    details[0]["scriptStackTraceElements"] as? [[String: AnyObject]] {
                        // There may not be a stacktrace if the script didn't start
                        // executing.
                        for trace in stacktrace {
                            let f = trace["function"] as? String ?? "Unknown"
                            let num = trace["lineNumber"] as? Int ?? -1
                            errMessage += "\t\(f): \(num)\n"
                        }
                }

                // Set the output as the compiled error message.
                output.text = errMessage
            } else {
                // The result provided by the API needs to be cast into the
                // correct type, based upon what types the Apps Script function
                // returns. Here, the function returns an Apps Script Object with
                // String keys and values, so must be cast into a Dictionary
                // (folderSet).
                let response = object.JSON["response"] as! [String: AnyObject]
                let folderSet = response["result"] as! [String: AnyObject]
                if folderSet.count == 0 {
                    output.text = "No folders returned!\n"
                } else {
                    var folderString = "Folders under your root folder:\n"
                    for (id, folder) in folderSet {
                        folderString += "\t\(folder) (\(id))\n"
                    }
                    output.text = folderString
                }
            }
    }

    // Creates the auth controller for authorizing access to Google Apps Script Execution API
    private func createAuthController() -> GTMOAuth2ViewControllerTouch {
   // Error** Use of undeclared type 'GTLServiceTicket'     let scopeString = " ".join(scopes) // Error*  'join' is unavailable: call the 'joinWithSeparator()' method on the sequence of elements
        return GTMOAuth2ViewControllerTouch(
            scope: scopeString,
            clientID: kClientID,
            clientSecret: nil,
            keychainItemName: kKeychainItemName,
            delegate: self,
            finishedSelector: "viewController:finishedWithAuth:error:"
        )
    }

    // Handle completion of the authorization process, and update the Google Apps Script Execution API
    // with the new credentials.
    func viewController(vc : UIViewController,
        finishedWithAuth authResult : GTMOAuth2Authentication, error : NSError?)
  // Error** Use of undeclared type 'GTMOAuth2Authentication' {

            if let error = error {
                service.authorizer = nil
                showAlert("Authentication Error", message: error.localizedDescription)
                return
            }

            service.authorizer = authResult
            dismissViewControllerAnimated(true, completion: nil)
    }

    // Helper for showing an alert
    func showAlert(title : String, message: String) {
        let alert = UIAlertView(
            title: title,
            message: message,
            delegate: nil,
            cancelButtonTitle: "OK"
        )
        alert.show()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}