I am trying to move a picture in Xcode 8. I have the code for it, but the image won't move when the button is pressed. Can someone please help me solve the problem for the picture not moving.
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.
}
*/
}
Delete your button from your code and then right click on your button and click on the "x" to remove the connection to the old code.
Now add the button back. I think your button was setup wrong. when you right click the botton look and see what the Send Event was. It should be setup this way.
If this is the answer you were looking for don't forget to except the answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.