gpt4 book ai didi

ios - 动画按钮允许用户交互不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 22:06:27 25 4
gpt4 key购买 nike

我在 NSObject 类的代码中创建了一个 UIbutton,它控制 UIViewController 类中的游戏。该按钮在游戏的大部分时间都可以正常工作,但在某个时刻我希望该按钮淡入/淡出。一旦淡入/淡出开始动画,按钮就不再具有交互性。我已经设置了 .AllowUserInteraction 选项,但仍然没有运气。我被这个难住了,所以非常感谢任何帮助!

Class GameController: NSObject {
var gameView: UIView!
var nextButton: UIButton!

func gameViewSetUp() {
// create the nextButton
let imageNextButton = UIImage(named: "rightArrow") as UIImage?
self.nextButton = UIButton(type: .Custom)
nextButton.frame = CGRectMake(ScreenWidth-100,ScreenHeight-250,60,60)
nextButton.setTitle("", forState: UIControlState.Normal)
nextButton.setImage(imageNextButton, forState: .Normal)
nextButton.contentMode = .ScaleAspectFill
nextButton.backgroundColor = UIColor.clearColor()
nextButton.layer.cornerRadius = 5.0
nextButton.layer.borderWidth = 2.5
nextButton.layer.borderColor = UIColor.clearColor().CGColor
nextButton.addTarget(self, action: "nextPressed", forControlEvents: .TouchUpInside)
nextButton.userInteractionEnabled = true
gameView.addSubview(nextButton)

func playStageX() {
nextButtonWink()
}
}

func nextButtonWink() {
UIView.animateWithDuration(1.5, delay: 0, options: [.AllowUserInteraction, .Repeat, .CurveEaseInOut, .Autoreverse],
animations: {
// self.nextButton.userInteractionEnabled = true // I tried this as well but no impact.
self.nextButton.alpha = 0
}, completion: nil)
}

class GameViewController: UIViewController {
private var controller: GameController
required init?(coder aDecoder: NSCoder) {
controller = GameController()
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
let gameView = UIView(frame: CGRectMake(0, 0, ScreenWidth, ScreenHeight))
self.view.addSubview(gameView)
controller.gameView = gameView

最佳答案

取出 self.nextButton.alpha = 0 来测试一下,我相信当 alpha 为零时按钮事件不会触发。在动画方面,实际对象的 alpha 将在动画开始之前设置为零,您所看到的就像是动画时 View 的渲染交互式屏幕截图

如果是这种情况,那么您需要将 alpha 设置为类似 0.0100000003 或覆盖按钮以在 alpha 0 处进行交互

关于ios - 动画按钮允许用户交互不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34296002/

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