I have a UIImageView which moves across the screen, but I would like the image to rotate so the top of the image is facing the direction of motion.
func shootStar(backgroundImage: UIImageView){
let screenSize = UIScreen.main.bounds
let screenHeight = screenSize.height
let screenWidth = screenSize.width
let star = UIImage(named: "Shooting Star")
let starView = UIImageView(image: star!)
starView.frame = CGRect(x: -40,y: screenHeight*0.05, width: 38.5, height: 42.8)
view.insertSubview(starView, aboveSubview: backgroundImage)
let toPoint:CGPoint = CGPoint(x: screenWidth + 80, y: screenHeight*0.3)
let fromPoint:CGPoint = CGPoint(x: -40, y: 40)
let movement = CABasicAnimation(keyPath: "position")
movement.isAdditive = true
movement.fromValue = NSValue(cgPoint: fromPoint)
movement.toValue = NSValue(cgPoint: toPoint)
movement.duration = 5
starView.layer.add(movement, forKey: "move")
}