2017-12-09 106 views
5

enter image description hereLàm thế nào để thêm dấu thời gian hiện tại trong máy ảnh trong ứng dụng ios

Something như thế này tôi muốn thêm dấu thời gian hiện nay khi ghi âm được thực hiện trong đoạn video và lưu vào thư viện ảnh.

** Lưu ý **: Tôi đã thêm thành công vị trí hiện tại và timestamp trong AVVideoPreviewLayer nhưng nó là tĩnh sau khi xuất video được hiển thị thời gian tĩnh không hiển thị chạy timestamp

Trả lời

1

tôi đã cố gắng một cái gì đó. Tôi đoán bạn muốn có được vĩ độ, kinh độ và dấu thời gian.

Bạn tìm thấy ví dụ về vĩ độ và kinh độ bên dưới.

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)") 
    } 
} 

Để có được thời gian hiện tại bạn có thể sử dụng một cái gì đó như thế này:

let date = NSDate() 
print(date) 

Kết quả cho cả hai trong giao diện điều khiển nên tìm một cái gì đó như thế này:

2017-12-17 21:45:39 +0000 
user latitude = 37.3322499 
user longitude = -122.056264 

(Hiện trông giống như điều này trong ví dụ của tôi vì im từ EU nhưng bạn có thể chuyển đổi nó thành những gì bạn muốn)

Bạn có thể thêm phần này vào chế độ xem riêng và đưa nó lên phía trước với

view.bringSubview(toFront: YourView) 

Tôi hy vọng điều này hữu ích!

+0

Xin chào, Ứng dụng có hoạt động không? –

Các vấn đề liên quan