像这样的东西我想在视频中完成录制时添加当前时间戳并保存到相机胶卷中。
**注意**:我已经成功添加了AVVideoPreviewLayer中的当前位置和时间戳,但是在导出视频后它是静态的显示静态时间没有显示运行时间戳
尝试创建一个previewLayer:UIView图层,其中包含您想要在相机上使用的组件。
将此图层添加到当前正在运行的AVCaptureVideoPreviewLayer会话中。
此链接可能有助于您解决问题
Adding objects over camera view in app (Swift 3) not under camera view?
我试了一下。我想你想获得纬度,经度和时间戳。
您可以在下面找到纬度和经度的示例。
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showLocation(_ sender: Any) {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if(CLLocationManager.locationServicesEnabled()){
locationManager.startUpdatingLocation()
}
locationManager.stopUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
print("user latitude = \(userLocation.coordinate.latitude)")
print("user longitude = \(userLocation.coordinate.longitude)")
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)
{
print("Error \(error)")
}
}
要获得当前时间,您可以使用以下内容:
let date = NSDate()
print(date)
在控制台中的结果应该如下所示:
2017-12-17 21:45:39 +0000
user latitude = 37.3322499
user longitude = -122.056264
(在我的例子中,时间看起来像这样,因为我来自欧盟,但你可以把它转换成你想要的)
您可以将其添加到单独的视图中并将其置于最前面
view.bringSubview(toFront: YourView)
我希望这是有帮助的!