[英]Move object in straight line swift
我有一個圖像,我需要將它沿直線移動,例如從 (x, y) 到 (x1, y2)。
移動后如何使圖像消失?
我試圖這樣做,但我不知道下一步該怎么做。
@IBOutlet weak var moveobj: UIImageView!
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
linePath.move(to: CGPoint(x: 100, y: 100))
linePath.addLine(to: CGPoint(x: 300, y: 300))
moveobj.layer .addAnimation(path, forKey: "path")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Set the image view in the starting location
moveobj.frame = CGRect(x: 100, y: 100, width: /* some width */, height: /* some height */)
UIView.animate(withDuration: /* some duration */, animations: {
// Move image view to new location
self.moveobj.frame = CGRect(x: 300, y: 300, width: self.moveobj.frame.width, height: self.moveobj.frame.height)
}) { (finished) in
// Animation completed; hide the image view
self.moveobj.isHidden = true
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.