如何在Xcode 6上访问相机库

时间:2015-04-24 02:44:40

标签: ios swift

我正在使用swift开发一个非常简单的iPhone应用程序,您可以在其中拍照并将其保存到解析中。

我想知道在哪里可以找到访问相机库的文档,因为我发现的唯一的东西就是快速文档。

关于如何解决这个问题的任何建议都会非常有用。

2 个答案:

答案 0 :(得分:1)

Base class says: hello makeInstance1 built a BaseClass I think it is a __lldb_expr_89.SubClass Base class says: hello makeInstance2 built a BaseClass I think it is a __lldb_expr_89.BaseClass 是您要实施的对象。 Apple的文档在页面顶部有一个swift / objective-c切换。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class/

答案 1 :(得分:0)

您必须使用UIImagePickerController。 Here's官方Apple文档。

  1. 确保您的视图控制器符合UIImagePickerControllerDelegate

    class ViewController: UIViewController,UIImagePickerControllerDelegate
    
  2. 检查用户的设备是否有摄像头(很多人忘了这样做)。

    if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { 
        // if the user's device has a camera, set the source type to camera
        picker!.sourceType = UIImagePickerControllerSourceType.Camera
        // present the picker view controller
        self.presentViewController(picker, animated: true, completion: nil)
    }
    
  3. 实施委托方法

    func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) {
        // dismiss the picker controller
        picker.dismissViewControllerAnimated(true, completion: nil)
        // retrieve the image
        var image = info[UIImagePickerControllerOriginalImage] as UIImage
    }
    
    func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
        // user cancelled
    }