我正在研究用于分割的相机应用程序,我设法捕获了实时照片以缩略图形式显示在UIImageView中。现在,如果用户不触摸,我希望它在3秒钟内消失(例如,拍照时IOS相机的行为)。您能帮我实现目标吗?请在下面查看我的代码的相关部分。预先非常感谢。
// MARK: -- action to Capture Photo
extension ViewController {
@IBaction func photoButtonaction(sender: UIButton) {
CameraManager.shared.capture { [weak self] (pixelBuffer,sampleBuffer) in
self?.handleCameraOutput(pixelBuffer: pixelBuffer,sampleBuffer: sampleBuffer,onFinish: { (image) in
self?.imagePreview.image = image
let pngData = image!.pngData()
let compressedData = UIImage(data: pngData!)
self!.writeToPhotoAlbum(image: compressedData!)
})
}
}
func writeToPhotoAlbum(image: UIImage) {
UIImageWriteToSavedPhotosAlbum(image,self,#selector(saveError),nil)
}
@objc func saveError(_ image: UIImage,didFinishSavingWithError error: Error?,contextInfo: UnsafeRawPointer) {
}
}