メモ
MKMapViewの directionの取り方と、回転
let direction = self.mapView!.camera.heading
let angle : Double = (-1 * direction * Double.pi) / 180
self.targetView!.transform = CGAffineTransform(rotationAngle: CGFloat(angle))
画像の回転を制御したい
こう書いてしまうと
self.targetView!.transform = self.targetView!.transform.rotated(by: gesture.rotation)
グリングリン回りすぎる。。
↓
if(gesture.state == .began || gesture.state == .changed) {
let roundedRotation = round(gesture.rotation*10)/10
if(roundedRotation != beforeRotation) { // 回転量を調整する
self.gisView!.transform = self.gisView!.transform.rotated(by: roundedRotation)
}
beforeRotation = roundedRotation
}
これで無理やり調整。
let direction = self.mapView!.camera.heading
if(gesture.state == .began || gesture.state == .changed) {
// 回転量を調整する
let roundedRotation = round(gesture.rotation*10)/10
if(roundedRotation != beforeRotation) {
self.gisView!.transform = self.gisView!.transform.rotated(by: roundedRotation)
self.mapView!.camera.heading = direction + CLLocationDirection (gesture.rotation*100) * (-1)
}
beforeRotation = roundedRotation
}
地図も一緒に回転するようにした!