0
1

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 3 years have passed since last update.

6日目(1/2個):ボタンを押すと画像が動くようにする

Posted at

#6日目のアプリ
トリガーがボタンの画像アニメーション

##画面キャプチャ

##以下の流れで作りました。

  1. storyboadに1つのUIImageViewと1つのボタンを配置(パンダは自作)
  2. 上記要素をViewController.swiftへoptionドラッグして紐付ける
  3. 紐付けができたら、ViewController.swiftでコードを書く

##できたこと

  • 画像の移動方法がわかった。
  • 移動と、拡大縮小、その他諸々の方法がある。
    ##書いたコードを共有します!

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var Panda: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func buttonTapped(_ sender: Any) {
        UIView.animate(withDuration: 1.0, animations: {
            self.Panda.transform = CGAffineTransform(translationX: 0, y: -1000)
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: {
                self.Panda.transform = CGAffineTransform.identity
            })
        }
    }

}

##感想
6日目。パンダが思いのほかうまくかけた。

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?