UIImageView가 화면을 가로 질러 이동하지만, 이미지의 위쪽이 모션 방향을 향하도록 이미지를 회전시키고 싶습니다.UIImageView를 이동 방향에 따라 회전하십시오.
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")
}
가능한 중복/questions/31421912/rotate-an-object-in-its-direction-of-motion) –
이것은 UIImageViews가 아닌 스프라이트 –
과 관련이 없습니다. 당신이 필요로하는 것은 회전 각 (zRotation)입니다. –