1 // Copyright 2016-present 650 Industries. All rights reserved. 2 3 extension UIImagePickerController { fixCannotMoveEditingBoxnull4 func fixCannotMoveEditingBox() { 5 if let cropView = cropView, 6 let scrollView = scrollView, 7 scrollView.contentOffset.y == 0 8 { 9 let top = cropView.frame.minY + self.view.safeAreaInsets.top 10 let bottom = scrollView.frame.height - cropView.frame.height - top 11 scrollView.contentInset = UIEdgeInsets(top: top, left: 0, bottom: bottom, right: 0) 12 13 var offset: CGFloat = 0 14 if scrollView.contentSize.height > scrollView.contentSize.width { 15 offset = 0.5 * (scrollView.contentSize.height - scrollView.contentSize.width) 16 } 17 scrollView.contentOffset = CGPoint(x: 0, y: -top + offset) 18 } 19 20 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in 21 self?.fixCannotMoveEditingBox() 22 } 23 } 24 25 var cropView: UIView? { 26 return findCropView(from: self.view) 27 } 28 29 var scrollView: UIScrollView? { 30 return findScrollView(from: self.view) 31 } 32 findCropViewnull33 func findCropView(from view: UIView) -> UIView? { 34 let width = UIScreen.main.bounds.width 35 let size = view.bounds.size 36 if width == size.height, width == size.height { 37 return view 38 } 39 for view in view.subviews { 40 if let cropView = findCropView(from: view) { 41 return cropView 42 } 43 } 44 return nil 45 } 46 findScrollViewnull47 func findScrollView(from view: UIView) -> UIScrollView? { 48 if let scrollView = view as? UIScrollView { 49 return scrollView 50 } 51 for view in view.subviews { 52 if let scrollView = findScrollView(from: view) { 53 return scrollView 54 } 55 } 56 return nil 57 } 58 } 59