I created a button and set some animations too it but now I can not tap it or interact with it while it is in motion and if it lets me tap it I get an error. My goal is to make the button disappear while it is moving when you click on it. Please help!! Thanks in advance!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// Create button
let button = UIButton.buttonWithType(UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 100)
button.setTitle("Test Button", forState: UIControlState.Normal)
button.addTarget(self, action: "buttonAction", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
UIView.animateWithDuration(4, delay: 3, options: UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.LayoutSubviews | UIViewAnimationOptions.Autoreverse, animations: {
button.frame = CGRectMake(100, 300, 100, 100)
}, completion: nil)
// Create a function that makes the button dissapear when it is tapped
func buttonAction() {
button.alpha = 0
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Aucun commentaire:
Enregistrer un commentaire