作業9#54 愛你最好的距離 ? slider & button 移動練習
Published in
Dec 27, 2021
時間不夠,只能用一個簡單版的
import UIKitclass ViewController: UIViewController {@IBOutlet weak var leftImageView: UIImageView!
@IBOutlet weak var rightImageView: UIImageView!
@IBOutlet weak var slider: UISlider!
@IBOutlet weak var sliderLabel: UILabel!
@IBOutlet weak var plane: UIImageView!
func planeLocation (degrees: CGFloat) {
plane.transform = CGAffineTransform.identity.rotated(by: CGFloat.pi / 180 * degrees).translatedBy(x: 150, y: 100)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}@IBAction func sliderMove(_ sender: UISlider) {
let speed = sender.value * 0.3
let sliderValue = slider.value
leftImageView.frame.origin.x = CGFloat(30 + speed)
rightImageView.frame.origin.x = CGFloat(308 - speed)
planeLocation(degrees: CGFloat(sender.value))
sliderLabel.text = "\(Int(sliderValue))"
}
}