lundi 23 mars 2015

Animate a normal button when pressed (in Swift)

I am trying to create a camera app. In the first screen, I would like to show the user only a camera button and when that's pressed, an image is taken an put in a View and the camerabutton needs to be replaced by other buttons ( a redo, share and save button).


However, when I try to animate them, I get an error and everything crashes. What did I do wrong here?



// variables of the bottom menu bar
@IBOutlet weak var cameraButton: UIButton!
@IBOutlet weak var redoButton: UIButton!
@IBOutlet weak var saveButton: UIButton!
@IBOutlet weak var shareButton: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
redoButton.center = CGPointMake(redoButton.center.x, redoButton.center.y - 400)
}

@IBAction func didTakePhoto(sender: AnyObject) {

UIView.animateWithDuration(1, animations: {() -> Void in

self.redoButton.center = CGPointMake(self.redoButton.center.x, self.redoButton.center.y + 400)
self.cameraButton.center = CGPointMake(self.cameraButton.center.x, self.cameraButton.center.y - 400)

})

}


The error I get is a breakpoint at self.cameraButton.center = CGPointMake(self.cameraButton.center.x, self.cameraButton.center.y - 400)


Thanks in advance for your help! I am beginner and enjoying it a lot.




Aucun commentaire:

Enregistrer un commentaire