{"id":2477,"date":"2025-02-22T21:48:39","date_gmt":"2025-02-22T13:48:39","guid":{"rendered":"https:\/\/www.xfan.top\/?p=2477"},"modified":"2025-02-22T21:48:39","modified_gmt":"2025-02-22T13:48:39","slug":"ios%e4%bd%bf%e7%94%a8uiimagepickercontroller%e6%8b%8d%e6%91%84%e5%b9%b6%e8%a3%81%e5%89%aa%e7%85%a7%e7%89%87%e6%97%b6%ef%bc%8c%e8%a3%81%e5%89%aa%e6%a1%86%e6%97%a0%e6%b3%95%e6%8b%96%e5%8a%a8%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.xfan.top\/index.php\/2025\/02\/22\/2477\/","title":{"rendered":"IOS\u4f7f\u7528UIImagePickerController\u62cd\u6444\u5e76\u88c1\u526a\u7167\u7247\u65f6\uff0c\u88c1\u526a\u6846\u65e0\u6cd5\u62d6\u52a8\u7684\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<p>\u53c2\u8003\uff1a<a href=\"https:\/\/stackoverflow.com\/questions\/12630155\/uiimagepicker-allowsediting-stuck-in-center\/53440254#53440254\">https:\/\/stackoverflow.com\/questions\/12630155\/uiimagepicker-allowsediting-stuck-in-center\/53440254#53440254<\/a><\/p>\n<pre><code class=\"language-swift\">extension UIImagePickerController {\n    open override var childForStatusBarHidden: UIViewController? {\n        return nil\n    }\n\n    open override var prefersStatusBarHidden: Bool {\n        return true\n    }\n\n    open override func viewDidLayoutSubviews() {\n        super.viewDidLayoutSubviews()\n        fixCannotMoveEditingBox()\n    }\n\n    private func fixCannotMoveEditingBox() {\n        if let cropView = cropView, let scrollView = scrollView, scrollView.contentOffset.y == 0 {\n            let top: CGFloat = cropView.frame.minY + self.view.frame.minY\n            let bottom = scrollView.frame.height - cropView.frame.height - top\n            scrollView.contentInset = UIEdgeInsets(top: top, left: 0, bottom: bottom, right: 0)\n\n            var offset: CGFloat = 0\n            if scrollView.contentSize.height &gt; scrollView.contentSize.width {\n                offset = 0.5 * (scrollView.contentSize.height - scrollView.contentSize.width)\n            }\n            scrollView.contentOffset = CGPoint(x: 0, y: -top + offset)\n        }\n\n        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in\n            self?.fixCannotMoveEditingBox()\n        }\n    }\n\n    private var cropView: UIView? {\n        return findCropView(from: self.view)\n    }\n\n    private var scrollView: UIScrollView? {\n        return findScrollView(from: self.view)\n    }\n\n    private func findCropView(from view: UIView) -&gt; UIView? {\n        let width = UIScreen.main.bounds.width\n        let size = view.bounds.size\n        if width == size.height, width == size.height {\n            return view\n        }\n        for view in view.subviews {\n            if let cropView = findCropView(from: view) {\n                return cropView\n            }\n        }\n        return nil\n    }\n\n    private func findScrollView(from view: UIView) -&gt; UIScrollView? {\n        if let scrollView = view as? UIScrollView {\n            return scrollView\n        }\n        for view in view.subviews {\n            if let scrollView = findScrollView(from: view) {\n                return scrollView\n            }\n        }\n        return nil\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\uff1ahttps:\/\/stackoverflow.com\/questions\/12630155\/uiimage [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2477","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/comments?post=2477"}],"version-history":[{"count":3,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2477\/revisions"}],"predecessor-version":[{"id":2523,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2477\/revisions\/2523"}],"wp:attachment":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/media?parent=2477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/categories?post=2477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/tags?post=2477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}