iPad選擇照片時(shí)的問(wèn)題
如果你指定了Devices為iPhone,那么iPad仍然可以以模擬方式運(yùn)行APP,但是在使用UIImagePickerController選擇照片時(shí),有可能出現(xiàn)縮略圖無(wú)法顯示的Bug(如圖),這個(gè)應(yīng)該是官方的Bug。

1.png
解決方案A:不限制設(shè)備類型
TARGETS - Deployment Info - Devices :Universal
這樣意味著你的App要完全兼容和適配iPad,代碼改動(dòng)量較大。
解決方案B:使用Photokit或第三方類庫(kù)
目前我用的是一個(gè)OC的類庫(kù):https://github.com/banchichen/TZImagePickerController
遺憾的是Swift需要橋接了。為了不影響之前的體驗(yàn),當(dāng)判斷為iPad時(shí)再調(diào)用這個(gè)類庫(kù)方法來(lái)選擇圖片。如:
func pushImagePickerView() {
func setColorAndPresent(controller: UINavigationController) {
controller.navigationBar.tintColor = navigationController?.navigationBar.tintColor
controller.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
controller.navigationBar.barTintColor = navigationController?.navigationBar.barTintColor
presentViewController(controller, animated: true, completion: nil)
}
if Device.type() == .iPad {
let controller = TZImagePickerController(maxImagesCount: 1, columnNumber: 4, delegate: self)
controller.allowPickingVideo = false
controller.allowTakePicture = false
controller.allowPickingOriginalPhoto = false
controller.oKButtonTitleColorNormal = UIColor.whiteColor()
setColorAndPresent(controller)
} else {
let controller = UIImagePickerController()
controller.sourceType = .PhotoLibrary
controller.delegate = self
setColorAndPresent(controller)
}
}
其中 { Device.type() == .iPad } 使用了第三方類Device,你可以換用自己的方法。
文中如有不妥之處,歡迎指正!