我正在尝试为MKAnnotation旋转图像,当我成功完成时,它的标题也在旋转。有没有办法让标题保持平稳?任何帮助将非常感激!
这是我的代码:
在viewDidLoad()...
中let middlePoint = CustomPointAnnotation()
middlePoint.coordinate = self.coordinates
middlePoint.imageName = "routemiddle"
middlePoint.title = "\(hourDetailedRoute):\(minuteDetailedRoute)"
middlePoint.courseDegrees = self.vehicleChangeCourse
self.mapa.addAnnotation(middlePoint)
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is CustomPointAnnotation) {
return nil
}
let reuseId = "annotation"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView!.canShowCallout = true
}
else {
anView!.annotation = annotation
}
let cpa = annotation as! CustomPointAnnotation
anView!.image = UIImage(named:cpa.imageName)
anView!.transform = CGAffineTransformRotate(self.mapa.transform, CGFloat(degreesToRadians(cpa.courseDegrees)))
return anView
}
class CustomPointAnnotation:MKPointAnnotation {
var imageName: String!
var courseDegrees = 0.0
}
答案 0 :(得分:0)
我已经弄明白了!我只需要旋转图像而不是旋转整个视图。
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<ToolBar prefWidth="600.0">
<items>
<Button fx:id="buttonPlay" mnemonicParsing="false" onAction="#handlePlayButtonAction" text="Play" />
<Button fx:id="buttonPause" mnemonicParsing="false" onAction="#handlePauseButtonAction" text="Pause" />
<Button fx:id="buttonStop" mnemonicParsing="false" onAction="#handleStopButtonAction" text="Stop" />
</items>
</ToolBar>
</children>
</Pane>
<Label fx:id="labelHelloWorld" text="Hello World!" />
</children>
</StackPane>