#54.slider練習: 愛你最好的距離?

➤作業目的:學習偵測slider 的value 變化

喂女孩妳要去哪啊?! 跑過頭啦~~~~~~~

(模擬器跑起來當當的,請見諒><)

上圖為「奔跑的女孩」與「原地等待的男孩」,由Vinnie繪製
import UIKitclass ViewController: UIViewController {@IBOutlet weak var girl: UIImageView!@IBOutlet weak var boy: UIImageView!override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.}@IBAction func run(_ sender: UISlider) {let speed=sender.value*15girl.frame.origin.x = CGFloat(50+speed*6)boy.frame.origin.x = CGFloat(600-speed)}}

--

--