我有一个图像,我需要将它沿直线移动,例如从(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")
}
答案 0 :(得分:0)
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
}
}