Skip to content

Files

Latest commit

 

History

History
50 lines (38 loc) · 2.12 KB

001.md

File metadata and controls

50 lines (38 loc) · 2.12 KB

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


文中如有不妥之处,欢迎指正!