隐藏后 5 秒显示图像

Display image 5 second after hidden

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
    }
}

动画完成后图像被隐藏,但我想在 5 秒后在原始位置再次显示。我该怎么做?

好吧,您所要做的就是将一个新动画链接到完成,该动画与之前的动画相反(移回原始位置并取消隐藏)-由@Rob 的评论提供。

只是:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    // Set the image view in the starting location

    let originalFrame = CGRect(x: 100, y: 100, width: /* some width */,                   
    height: /* some height */)
    moveobj.frame = originalFrame

    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
        // Next animation
        DispatchQueue.main.asyncAfter(deadline: .now() + 5){
            self.moveobj.frame = originalFrame
            self.moveobj.isHidden = false
        }
    }
}