Swift 直线移动对象

Swift 直线移动对象,swift,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)) linePat

我有一个图像,我需要在一条直线上移动它,例如从(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")
}

通过执行
moveobj.ishiden=true
ok谢谢,现在如何移动?我有一个错误是“UIView.animation(withDuration:/*some duration*/,animations:{…}”它的say类型“UIView”没有成员“animation”我现在是怎么做的?谢谢你回答我的拼写错误。应该是
animate(withDuration:…)
因为它仍然是相同的erro
animate(withDuration:…)
UIView
上的一个类函数。所以
UIView
是必需的,例如
UIView.animate(withDuration:…)
。已经同意了,谢谢,但是现在我有一个erro,它的值为'UIImageView'的类型没有成员'isHidden'
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
    }
}