takePicture()with cameraOverlayView

时间:2015-03-20 19:01:38

标签: swift

我正在使用cameraOverlayView创建自定义相机。但是,我不知道如何让按钮拍摄照片。 Apple Docs说takePicture()是要使用的功能。但它没有编译:

两种尝试均无效:

let shootPicture = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera, target: self, action: takePicture())

let shootPicture = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera, target: self, { action -> Void in
            takePicture()
        })

更新后的尝试:

let shootPicture = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera,  style: UIBarButtonItemStyle.Plain, target: self, action: "takePicture")

// separate function
func takePicture() {
        imagePicker.takePicture()
}

仍然出现语法错误:missing argument for parameter 'landscapeImagePhone' in call

但是当我添加landscapeImagePhone: UIBarButtonSystemItem.Camera时,我在调用中得到“额外参数'landscapeImagePhone'”

1 个答案:

答案 0 :(得分:0)

对于其他坚持这一点的人:

设置栏项目:

let shootPicture = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera,  target: self, action: "takePicture")

创建函数

func takePicture() {
    imagePicker.takePicture()
}