升級(jí)到iOS11后,使用UIImagePickerController拍照或選擇相冊(cè)圖片道媚,并設(shè)置
let vc = UIImagePickerController()
vc.allowsEditing = true
進(jìn)行編輯圖片時(shí)扁掸,發(fā)現(xiàn)圖片無論怎么拖,都無法對(duì)準(zhǔn)到編輯框衰琐,甚至選出來的圖片
let image = info[UIImagePickerControllerEditedImage] as? UIImage
會(huì)帶有黑邊也糊,莫名被剪掉了一些內(nèi)容...
解決辦法是讓其導(dǎo)航欄透明:
extension ViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
// iOS11需要讓導(dǎo)航欄透明炼蹦,否則圖片對(duì)不準(zhǔn)選擇框羡宙,選出的圖片也會(huì)有黑邊
if navigationController is UIImagePickerController {
navigationController.navigationBar.isTranslucent = true
}
}
}
當(dāng)App的導(dǎo)航欄被默認(rèn)設(shè)置了全局背景圖時(shí),就會(huì)失去透明掐隐,比如
let bar = UINavigationBar.appearance()
bar.setBackgroundImage(image, for: .default)
這種情況下狗热,調(diào)起UIImagePickerController時(shí),它的導(dǎo)航欄就是不透明的虑省,需要處理一下匿刮。