|
@@ -27,15 +27,21 @@ class PhotoAndCameraManager: NSObject {
|
|
|
/// 相册
|
|
|
func authorizePhoto() {
|
|
|
|
|
|
- LBXPermissions.authorizePhotoWith {
|
|
|
- [weak self] (granted) in
|
|
|
- guard let strongSelf = self else { return }
|
|
|
-
|
|
|
+ weak var weakself = self
|
|
|
+ LBXPermissions.authorizePhotoWith { (granted) in
|
|
|
if granted {
|
|
|
let picker = UIImagePickerController()
|
|
|
picker.sourceType = UIImagePickerController.SourceType.photoLibrary
|
|
|
- picker.delegate = strongSelf
|
|
|
- picker.allowsEditing = strongSelf.isEditedImage
|
|
|
+ picker.delegate = weakself
|
|
|
+ picker.allowsEditing = weakself?.isEditedImage ?? true
|
|
|
+ picker.navigationController?.navigationBar.isTranslucent = false
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ UIScrollView.appearance().contentInsetAdjustmentBehavior = .automatic
|
|
|
+ } else {
|
|
|
+ if self.responds(to: #selector(setter: picker.automaticallyAdjustsScrollViewInsets)) {
|
|
|
+ picker.automaticallyAdjustsScrollViewInsets = true
|
|
|
+ }
|
|
|
+ }
|
|
|
getCurrentVC()?.present(picker, animated: true, completion: nil)
|
|
|
} else {
|
|
|
LBXPermissions.jumpToSystemPrivacySetting()
|
|
@@ -46,14 +52,21 @@ class PhotoAndCameraManager: NSObject {
|
|
|
|
|
|
/// 相机
|
|
|
func authorizeCamera() {
|
|
|
- LBXPermissions.authorizeCameraWith {
|
|
|
- [weak self] (granted) in
|
|
|
- guard let strongSelf = self else { return }
|
|
|
+ weak var weakself = self
|
|
|
+ LBXPermissions.authorizeCameraWith { (granted) in
|
|
|
if granted {
|
|
|
let picker = UIImagePickerController()
|
|
|
picker.sourceType = UIImagePickerController.SourceType.camera
|
|
|
- picker.delegate = strongSelf;
|
|
|
- picker.allowsEditing = strongSelf.isEditedImage
|
|
|
+ picker.delegate = weakself
|
|
|
+ picker.allowsEditing = weakself?.isEditedImage ?? true
|
|
|
+ picker.navigationController?.navigationBar.isTranslucent = false
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ UIScrollView.appearance().contentInsetAdjustmentBehavior = .automatic
|
|
|
+ } else {
|
|
|
+ if self.responds(to: #selector(setter: picker.automaticallyAdjustsScrollViewInsets)) {
|
|
|
+ picker.automaticallyAdjustsScrollViewInsets = true
|
|
|
+ }
|
|
|
+ }
|
|
|
getCurrentVC()?.present(picker, animated: true, completion: nil)
|
|
|
} else {
|
|
|
LBXPermissions.jumpToSystemPrivacySetting()
|
|
@@ -64,6 +77,13 @@ class PhotoAndCameraManager: NSObject {
|
|
|
|
|
|
extension PhotoAndCameraManager : UIImagePickerControllerDelegate,UINavigationControllerDelegate {
|
|
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
|
|
|
+ } else {
|
|
|
+ if self.responds(to: #selector(setter: picker.automaticallyAdjustsScrollViewInsets)) {
|
|
|
+ picker.automaticallyAdjustsScrollViewInsets = false
|
|
|
+ }
|
|
|
+ }
|
|
|
//查看info对象
|
|
|
//显示的图片
|
|
|
var image : UIImage? = info[.editedImage] as? UIImage
|
|
@@ -83,10 +103,21 @@ extension PhotoAndCameraManager : UIImagePickerControllerDelegate,UINavigationCo
|
|
|
|
|
|
//图片控制器退出
|
|
|
picker.dismiss(animated: true, completion: {
|
|
|
- () -> Void in
|
|
|
- if self.photoAndCameraManagerImageBlock != nil {
|
|
|
- self.photoAndCameraManagerImageBlock!(image!)
|
|
|
+ [weak self] () -> Void in
|
|
|
+ if self?.photoAndCameraManagerImageBlock != nil {
|
|
|
+ self?.photoAndCameraManagerImageBlock!(image!)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
|
|
|
+ } else {
|
|
|
+ if self.responds(to: #selector(setter: picker.automaticallyAdjustsScrollViewInsets)) {
|
|
|
+ picker.automaticallyAdjustsScrollViewInsets = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|