iPad選擇照片時(shí)的問(wèn)題

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,你可以換用自己的方法。


文中如有不妥之處,歡迎指正!


本文GitHub地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • github排名https://github.com/trending,github搜索:https://gith...
    小米君的demo閱讀 4,958評(píng)論 2 38
  • 16宿命:用概率思維提高你的勝算 以前的我是風(fēng)險(xiǎn)厭惡者,不喜歡去冒險(xiǎn),但是人生放棄了冒險(xiǎn),也就放棄了無(wú)數(shù)的可能。 ...
    yichen大刀閱讀 7,823評(píng)論 0 4
  • 公元:2019年11月28日19時(shí)42分農(nóng)歷:二零一九年 十一月 初三日 戌時(shí)干支:己亥乙亥己巳甲戌當(dāng)月節(jié)氣:立冬...
    石放閱讀 7,449評(píng)論 0 2
  • 今天上午陪老媽看病,下午健身房跑步,晚上想想今天還沒(méi)有斷舍離,馬上做,衣架和旁邊的的布衣架,一看亂亂,又想想自己是...
    影子3623253閱讀 3,062評(píng)論 3 8

友情鏈接更多精彩內(nèi)容