2017-04-21 6 views
0

次の背景画像にアニメーションを適用して、下に移動すると再び上がるはずです。私は1つの画像だけをアニメーション化したい。コードを実行すると、何とか画像が表示されません。 375高さ:幅以下のように画像の寸法は、ここでは666スウィフト、UIKitを使用して背景画像を連続的にアニメーション化する

を画像

ここでコードを使用でき

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

}

+0

こんにちは。私の答えをチェックしてください。それは動作しますか? –

答えて

2

ある[.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) 

希望します。 :)

関連する問題