QRCodeReaderViewController icon indicating copy to clipboard operation
QRCodeReaderViewController copied to clipboard

Delegate methods won't fire if I change presentation mode?

Open alezoffoli opened this issue 8 years ago • 2 comments

Both delegate methods fire just fine when I present it as modal like the example:

if QRCodeReader.isAvailable() {
            let reader: QRCodeReader = QRCodeReader(metadataObjectTypes: [AVMetadataObjectTypeQRCode])
            let vc: QRCodeReaderViewController = QRCodeReaderViewController(cancelButtonTitle: "Cancelar", codeReader: reader, startScanningAtLoad: true, showSwitchCameraButton: false, showTorchButton: false)

            vc.modalPresentationStyle = UIModalPresentationStyle.FormSheet
            vc.delegate = self
            self.presentViewController(vc, animated: true, completion: nil)
}

But if I insert a container view to my VC, and add the QRCodeReaderVC to it (so I can have a nice header menu, with some menu options and etc instead of modal), the delegate methods won't fire.

if QRCodeReader.isAvailable() {
            let reader: QRCodeReader = QRCodeReader(metadataObjectTypes: [AVMetadataObjectTypeQRCode])
            let vc: QRCodeReaderViewController = QRCodeReaderViewController(cancelButtonTitle: "Cancelar", codeReader: reader, startScanningAtLoad: true, showSwitchCameraButton: false, showTorchButton: false)

            vc.modalPresentationStyle = UIModalPresentationStyle.FormSheet
            vc.delegate = self

            self.addChildViewController(vc)
            vc.view.frame = CGRectMake(0, 0, self.containerView!.frame.size.width, self.containerView!.frame.size.height)
            self.containerView!.addSubview(vc.view)
            vc.didMoveToParentViewController(self)
        }

It behaves like this by design or am I doing something wrong?

alezoffoli avatar Feb 29 '16 01:02 alezoffoli

No, it's not normal. I'll test on my side and I'll be back with more informations.

yannickl avatar Mar 01 '16 17:03 yannickl

Here it works fine. However the reader don't stop automatically. We have to stop it manually calling the stopScanning method.

yannickl avatar Mar 01 '16 20:03 yannickl