iPad选择照片时的问题

iPad选择照片时的问题

如果你指定了Devices为iPhone,那么iPad仍然可以以模拟方式运行APP,但是在使用UIImagePickerController选择照片时,有可能出现缩略图无法显示的Bug(如图),这个应该是官方的Bug。


1.png

解决方案A:不限制设备类型

TARGETS - Deployment Info - Devices :Universal

这样意味着你的App要完全兼容和适配iPad,代码改动量较大。


解决方案B:使用Photokit或第三方类库

目前我用的是一个OC的类库:https://github.com/banchichen/TZImagePickerController
遗憾的是Swift需要桥接了。为了不影响之前的体验,当判断为iPad时再调用这个类库方法来选择图片。如:

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地址

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • github排名https://github.com/trending,github搜索:https://gith...
    小米君的demo阅读 4,882评论 2 38
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 6,131评论 0 4
  • 公元:2019年11月28日19时42分农历:二零一九年 十一月 初三日 戌时干支:己亥乙亥己巳甲戌当月节气:立冬...
    石放阅读 6,946评论 0 2
  • 今天上午陪老妈看病,下午健身房跑步,晚上想想今天还没有断舍离,马上做,衣架和旁边的的布衣架,一看乱乱,又想想自己是...
    影子3623253阅读 2,949评论 3 8