4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swiftで画像を動かす

Last updated at Posted at 2017-11-15

色々本を買ってswiftを勉強していたが、単純に画像を動かす方法がなかったのでメモ

繰り返し動かすTimerの方法はあったが、そうでなく単純に並行移動したい時

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var ushi: UIImageView!//動かしたい牛の画像
@IBOutlet weak var kuma: UIImageView!//動かしたいクマの画像

var animator: UIViewPropertyAnimator!


override func viewDidLoad() {
    super.viewDidLoad()
    
    animator = UIViewPropertyAnimator(duration:1.0,curve: .easeInOut){
        self.kuma.center.y += 500//これでクマの画像は下に
        self.ushi.center.x += 500//これで牛の画像は右に
    }
    

}

@IBAction func fallTapped(_ sender: Any) {
    //ボタンが押されたら、アニメーションがスタートする
    animator.startAnimation()
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

}

ボタンを何回も押したらそのぶん動くかと思ったが1回目のみしか動かないのが謎

4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?