Blame view

Twear/Motion(运动)/EndMotionVC.swift 5.72 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  //
  //  EndMotionVC.swift
  //  Twear
  //
  //  Created by yangbin on 2022/1/2.
  //
  
  import UIKit
  
  class EndMotionVC: UIViewController {
  
      
      private lazy var mapView: MAMapView = MAMapView()
      @IBOutlet weak var distanceLabel: UILabel!
      
      @IBOutlet weak var maxSpeedLabel: UILabel!
      @IBOutlet weak var minSpeedLabel: UILabel!
      @IBOutlet weak var timeLabel: UILabel!
      @IBOutlet weak var calorieLabel: UILabel!
      @IBOutlet weak var scrollView: UIScrollView!
      @IBOutlet weak var dateLabel: UILabel!
      
      @IBOutlet weak var averageSpeedLabel: UILabel!
      @IBOutlet weak var averagePaceLabel: UILabel!
      @IBOutlet weak var avatarImageView: UIImageView!
      @IBOutlet weak var motionTypeLabel: UILabel!
      var date: Date!
      var distance: Float!
      var length: Int!
      var calorie: Float!
      
      var coordinateArray: [CLLocationCoordinate2D] = []
      var speedArray: [Float] = []
      
      override func viewDidLoad() {
          super.viewDidLoad()
          initMapView()
          
          timeLabel.toTimeType3(length: length)
          calorieLabel.text = String(format:"%.2f", calorie) + LocString("千卡")
          distanceLabel.text = String(format:"%.2f", distance/1000)
          dateLabel.text = date.toString(.custom("yyyy.MM.dd HH:mm"))
          if let maxSpeed = speedArray.max() {
              maxSpeedLabel.text = "\(String(format:"%02d", Int(maxSpeed)/60))\(String(format:"%02d", Int(maxSpeed)%60))″"
          }
          if let minSpeed = speedArray.max() {
              maxSpeedLabel.text = "\(String(format:"%02d", Int(minSpeed)/60))\(String(format:"%02d", Int(minSpeed)%60))″"
          }
           let avgPace = speedArray.average()
              averagePaceLabel.text = "\(String(format:"%02d", Int(avgPace)/60))\(String(format:"%02d", Int(avgPace)%60))″/\(LocString("公里"))"
          
          averageSpeedLabel.text = "\(String(format:"%.2f", distance/1000/(Float(length)/60)))\(LocString("公里/小时"))"
          
          
          if let image = UIImage.getImageFromPath("avatar") {
              avatarImageView.image = image
          } else {
              avatarImageView.image = UIImage(named: UserInfo.gender == 1 ? "avatar_male" : "avatar_female")
          }
          
          scrollView.delegate = self
          // Do any additional setup after loading the view.
      }
      
      func initMapView() {
  //        MAMapView.updatePrivacyShow(.didShow, privacyInfo: .didContain)
  //        MAMapView.updatePrivacyAgree(.didAgree)
          
          mapView.showsUserLocation = false
  //        mapView.userTrackingMode = .follow
          mapView.showsCompass = false
          mapView.zoomLevel = 16
          mapView.mapLanguage = (AppSettings.shared.language == .Chinese) ? 0 : 1
          mapView.delegate = self
          
          let polyline = MAPolyline(coordinates: &self.coordinateArray, count: UInt(self.coordinateArray.count))
          mapView.add(polyline)
          
          let padding = UIEdgeInsets(top: 5, left: 5, bottom: 15, right: 5)
          mapView.setVisibleMapRect(polyline!.boundingMapRect, edgePadding: padding, animated: false)
          setPointAnnotation()
          
          mapView.frame = view.bounds
          view.addSubview(mapView)
          view.sendSubviewToBack(mapView)
    
      }
      
      func setPointAnnotation() {
          if coordinateArray.count > 1 {
              let startPoint = MAPointAnnotation()
              startPoint.coordinate = coordinateArray.first!
              startPoint.title = "起点"
              mapView.addAnnotation(startPoint)
              
              let stopPoint = MAPointAnnotation()
              stopPoint.coordinate = coordinateArray.last!
              stopPoint.title = "终点"
              mapView.addAnnotation(stopPoint)
          }
      }
      
      @IBAction func back(_ sender: Any) {
          presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
      }
      
      @IBAction func share(_ sender: Any) {
          let shareView = ShareView(view.screenSnapScreen())
          shareView.show()
      }
      
      
      deinit {
          print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
      }
  
  }
  
  extension EndMotionVC: UIScrollViewDelegate {
      
      func scrollViewDidScroll(_ scrollView: UIScrollView) {
  //        print(scr)
      }
  }
  
  extension EndMotionVC: MAMapViewDelegate {
      func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! {
          if let poly = overlay as? MAPolyline {
              let polylineView = MAPolylineRenderer(polyline: poly)
              polylineView!.lineWidth = 6
              polylineView!.strokeColor = UIColor(red: 4 / 255.0, green:  181 / 255.0, blue:  108 / 255.0, alpha: 1.0)
              polylineView!.lineJoinType = kMALineJoinRound
              polylineView!.lineCapType = kMALineCapRound
              return polylineView
          } else {
              return nil
          }
      }
      
      func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
          if annotation is MAPointAnnotation {
              let pointReuseIndetifier = "pointReuseIndetifier"
  //            let customAnnotation = annotation as! CustomPointAnnotation
              var annotationView: MAAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier)
              
              if annotationView == nil {
                  annotationView = MAAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
              }
              if annotation.title == "起点" {
                  annotationView?.image = UIImage(named: "start_point")
              }
              if annotation.title == "终点" {
                  annotationView?.image = UIImage(named: "stop_point")
              }
              annotationView?.centerOffset = CGPoint(x: 0, y: -7.5);
              return annotationView
          }
          return nil
      }
  }