簡體   English   中英

通過Xcode 8中的按鈕移動圖像

[英]moving an image by a button in Xcode 8

我正在嘗試在Xcode 8中移動圖片。我有相應的代碼,但是當按下按鈕時圖像不會移動。 有人可以幫我解決圖片不動的問題嗎?

import UIKit

class Level2ViewController: UIViewController {


 var image = UIImage(named: "ballon.png")

     var imageView = UIImageView(image: "ballon")//initialize properly, this is just for reference



    @IBAction func buttonPressed(_ sender: UIButton) {

            self.imageView.frame.origin.x += 50

    }


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

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


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

從代碼中刪除按鈕,然后右鍵單擊按鈕,然后單擊“ x”以刪除與舊代碼的連接。 在此處輸入圖片說明

現在,將按鈕添加回去。 我認為您的按鈕設置錯誤。 右鍵單擊botton外觀時,請查看發送事件是什么。 應該以這種方式設置。

如果這是您要找的答案,請不要忘記答案。

在此處輸入圖片說明

好的,我想我明白了。您需要控制將imageView拖到代碼中,並將其作為插座連接,然后移動imageView插座。 您正在移動變量。

在此處輸入圖片說明

在此處輸入圖片說明

如果這是您要找的答案,請不要忘記答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM