没有内置功能可以执行此操作,但通过在相机视图层次结构中添加一个将 alpha 设置为零的黑色 UIView 自己完成非常简单,然后播放系统声音并在“flash”视图的 alpha 动画时照片被拍摄。
在viewDidLoad、loadView、 或任何您组装视图层次结构的地方
// Assuming cameraView contains your previewLayer...
flashView = UIView(frame: <set your frame>)
flashView.alpha = 0
flashView.backgroundColor = UIColor.blackColor()
cameraView.addSubview(flashView)
Run Code Online (Sandbox Code Playgroud)
然后,在您的捕获完成块中
// Animate the "flash"
UIView.animateWithDuration(0.1, delay: 0, options: .Autoreverse, animations: { () -> Void in
flashView.alpha = 1
}, completion: nil)
// Play the camera shutter system sound
AudioServicesPlayAlertSound(1108)
Run Code Online (Sandbox Code Playgroud)
有关系统声音的更多信息,请参阅此问题:Playing system sound without importing your own .