I\'m using this code to make a custom camera crop:
UIImagePickerController editing view circle overlay
This works perfectly in camera roll but not taking pho
extension ProfileViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
guard imagePickerController?.sourceType == .camera else {
return
}
guard let view = viewController.view.subviews(deep: true, where: {
String(describing: type(of:$0)) == "CAMPreviewView"
}).first else {
return
}
viewController.view.layoutIfNeeded()
let camPreviewBounds = view.bounds
let circleRect = CGRect(
x: camPreviewBounds.minX + (camPreviewBounds.width - 320) * 0.5,
y: camPreviewBounds.minY + (camPreviewBounds.height - 320) * 0.5,
width: 320,
height: 320
)
let path = UIBezierPath(roundedRect: camPreviewBounds, cornerRadius: 0)
path.append(UIBezierPath(ovalIn: circleRect))
let layer = CAShapeLayer()
layer.path = path.cgPath
layer.fillRule = CAShapeLayerFillRule.evenOdd;
layer.fillColor = UIColor.black.cgColor
layer.opacity = 0.8;
view.layer.addSublayer(layer)
}
}