gpt4 book ai didi

ios - 如何在动画中点击按钮时使按钮消失

转载 作者:行者123 更新时间:2023-11-28 13:16:32 25 4
gpt4 key购买 nike

我创建了一个按钮并为它设置了一些动画,但现在我无法在它运动时点击它或与之交互,如果它允许我点击它,我会收到错误消息。我的目标是当你点击它时,让按钮在移动时消失。请帮忙!!提前致谢!

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.
}

最佳答案

为了修复崩溃,您需要将 buttonAction 函数移出 viewDidLoad 范围并像这样修改它:

func buttonAction(button: UIButton) {

button.alpha = 0
}

您还需要将 button.addTarget(...) param action 从这个“buttonAction”更改为这个“buttonAction:” .看下面的代码

button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)

关于ios - 如何在动画中点击按钮时使按钮消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28795012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com