我正在尝试在 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”以删除与旧代码的连接。
现在重新添加按钮。我认为你的按钮设置错误。 当您右键单击按钮时,查看发送事件是什么。 应该这样设置。
如果这是您正在寻找的答案,请不要忘记排除答案。
关于ios - 通过 Xcode 8 中的按钮移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41524362/