0

I implemented a scroll view and added three view controllers and one of them is a camera in order to read the QR code and change page to my main screen but the issue is when I swipe the screen it's so fast and when I want to change the page when camera detects the QR code the main page is coming so slow like a loading bar. Here is the implementation of the output of the data and changing the screen.

func captureOutput(captureOutput:AVCaptureOutput!,didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {

    let outputData:String
    var infoData = [String]()

    if metadataObjects == nil || metadataObjects.count == 0 {
        labelQR.text = "No QR code is detected"
        return
    }

    let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject

    if metadataObj.type  == AVMetadataObjectTypeQRCode{

        //After reading the QR code getting the string and split it to restaurant id and table number
        //and returning to the main menu to inform user about restaurant and table number
        if metadataObj.stringValue != nil{
            labelQR.text = metadataObj.stringValue
            outputData = metadataObj.stringValue
            infoData = outputData.characters.split{$0 == ":"}.map(String.init)

            //For debugging process
            print(infoData[0])
            print(infoData[1])

            //Changing the viewcontroller
            let aView = self.parentViewController! as! ViewController
            var frame:CGRect = aView.scrollView.frame
            frame.origin.x = frame.size.width
            frame.origin.y = 0
            aView.scrollView.scrollRectToVisible(frame, animated: true)

        }
    }
}

Is there any way to improve the speed of changing page ?

0 Answers0