ios - 在 UIImagePickerController 内的 UIBarButton 上添加系统摄像头

标签 ios swift uiimagepickercontroller

如果您熟悉 .PhotoLibraryUIImagePickerController 屏幕,右侧有一个取消按钮。在左侧,我想添加一个可以在 XCode 库中找到的相机图标。

我的代码不起作用。

let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .PhotoLibrary
picker.allowsEditing = true

let camera = UIBarButtonItem(barButtonSystemItem: .Camera, target: picker, action: Selector("btnOpenCamera"))
picker.navigationItem.leftBarButtonItem = camera

presentViewController(picker, animated: true, completion: nil)

最佳答案

引用这个post ,并将 objective-c 解释为 Swift。

我找到了解决问题的方法。此方法将在加载的 View Controller 中执行我需要的任何自定义。

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {

    let camera = UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: Selector("btnOpenCamera"))
    viewController.navigationItem.leftBarButtonItem = camera
}

关于ios - 在 UIImagePickerController 内的 UIBarButton 上添加系统摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35084038/

相关文章:

上传后 iOS UIImagePickerController 结果图像方向

ios - subview 中的 UIImagePickerController > 不是全屏

ios - 为什么我无法获取 firestore 子集合中存储的所有文档?

c++ - 在 Xcode C++ 项目中包含头文件

ios - 在重写 init 中访问 Realm 实例

ios - 为什么 XCode 6 中的示例 iOS 应用程序检查非可选变量的 nil?

iphone - "Could not load the kernel"启动相机 session 并尝试进行一些实时图像过滤

ios - Kal 日历演练

macOS 上的 Swift : open Chrome with a URL as parameter

ios - 选择图片后自动返回上传View Controller IOS7