Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用Swift、UIKit在循环中连续设置背景图像动画_Ios_Swift_Animatewithduration - Fatal编程技术网

Ios 使用Swift、UIKit在循环中连续设置背景图像动画

Ios 使用Swift、UIKit在循环中连续设置背景图像动画,ios,swift,animatewithduration,Ios,Swift,Animatewithduration,我想动画下面的背景图像,当它达到下降,它应该再次上升。我只想为一个图像设置动画。不知何故,当我运行代码时,图像是不可见的。图像尺寸如下:宽度:375,高度:666 这是图片 这是密码 import UIKit class ViewController: UIViewController { @IBOutlet weak var myView: UIView! var water:UIImageView! var hover:CABasicAnimation! override func

我想动画下面的背景图像,当它达到下降,它应该再次上升。我只想为一个图像设置动画。不知何故,当我运行代码时,图像是不可见的。图像尺寸如下:宽度:375,高度:666

这是图片

这是密码

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var myView: UIView!
var water:UIImageView!

var hover:CABasicAnimation!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    water = UIImageView(image: UIImage(named: "water"))
    water.frame = CGRect(x: 0, y: 0, width: 375.0, height: 666.0)

    water.contentMode = .scaleAspectFill

    UIView.animate(withDuration: 4.0, delay: 0, options: UIViewAnimationOptions.curveLinear, animations: {
        self.water.frame.origin.y = self.view.bounds.height + self.water.frame.height - 50

    }, completion: nil)

    self.view.insertSubview(water, aboveSubview: myView)





}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

您可以在动画中使用
[.repeat、.autoreverse]
选项

UIView.animate(withDuration: 4.0, delay: 0, options: [.repeat, .autoreverse, .curveLinear], animations: {
    self.water.frame.origin.y = self.view.bounds.height + self.water.frame.height - 50

}, completion: nil)

希望能有所帮助

您可以在动画中使用
[.repeat、.autoreverse]
选项

UIView.animate(withDuration: 4.0, delay: 0, options: [.repeat, .autoreverse, .curveLinear], animations: {
    self.water.frame.origin.y = self.view.bounds.height + self.water.frame.height - 50

}, completion: nil)

希望能有所帮助

嗨。请核对我的答案。行吗?嗨。请核对我的答案。它有用吗?