QRCodeReaderViewController
QRCodeReaderViewController copied to clipboard
Delegate methods won't fire if I change presentation mode?
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?
No, it's not normal. I'll test on my side and I'll be back with more informations.
Here it works fine. However the reader don't stop automatically. We have to stop it manually calling the stopScanning
method.