ios - 通过 Xcode 8 中的按钮移动图像

标签 ios swift cocoa-touch xcode8

我正在尝试在 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”以删除与旧代码的连接。 enter image description here

现在重新添加按钮。我认为你的按钮设置错误。 当您右键单击按钮时,查看发送事件是什么。 应该这样设置。

如果这是您正在寻找的答案,请不要忘记排除答案。

enter image description here

关于ios - 通过 Xcode 8 中的按钮移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41524362/

相关文章:

ios - "Thread 1: signal SIGTERM"在带有 iOS 的 xcode 中是什么意思?

ios - 无法快速将数据插入 UITableView

swift - 如何设置自动布局以使图像占据全屏?

swift - 如何在 Mac OS X 中向 SpriteKit 游戏添加窗口(首选项窗口)?

iphone - UINavigationBar 顶部的自定义 Logo ?

iphone - 如何获得 UIView 的正确大小?

ios - 使用 FMDB 的 SQLite : Insert record not working/no such table

ios - QuickBlox : Error while trying to login into QBChat in iOS 9

ios - 根据indexPath Swift在TableView中设置UiCell文本颜色

iphone - 在简单的应用程序中将模型链接到 Controller ?